1 /*
2  * Copyright 2008-2019 by Emeric Vernat
3  *
4  *     This file is part of Java Melody.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package net.bull.javamelody.internal.common;
19
20 import javax.servlet.http.HttpServletRequest;
21
22 import org.slf4j.Logger;
23
24 import net.bull.javamelody.JavaMelodyLogger;
25
26 /**
27  * {@link JavaMelodyLogger} pour Logback.
28  * @author Emeric Vernat
29  */

30 class LogbackLogger implements JavaMelodyLogger {
31     private static final Logger LOGGER = org.slf4j.LoggerFactory.getLogger(INTERNAL_LOGGER_NAME);
32
33     /** {@inheritDoc} */
34     @Override
35     public void debug(String msg) {
36         LOGGER.debug(msg);
37     }
38
39     /** {@inheritDoc} */
40     @Override
41     public void debug(String msg, Throwable throwable) {
42         LOGGER.debug(msg, throwable);
43     }
44
45     /** {@inheritDoc} */
46     @Override
47     public void info(String msg) {
48         LOGGER.info(msg);
49     }
50
51     /** {@inheritDoc} */
52     @Override
53     public void info(String msg, Throwable throwable) {
54         LOGGER.info(msg, throwable);
55     }
56
57     /** {@inheritDoc} */
58     @Override
59     public void warn(String msg, Throwable throwable) {
60         LOGGER.warn(msg, throwable);
61     }
62
63     /** {@inheritDoc} */
64     @Override
65     public void logHttpRequest(HttpServletRequest httpRequest, String requestName, long duration,
66             boolean systemError, int responseStatus, long responseSize, String loggerName) {
67         final Logger logger = org.slf4j.LoggerFactory.getLogger(loggerName);
68         if (logger.isInfoEnabled()) {
69             logger.info(LOG.buildLogMessage(httpRequest, duration, systemError, responseStatus,
70                     responseSize));
71         }
72     }
73 }
74