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 net.bull.javamelody.JavaMelodyLogger;
23
24 /**
25  * {@link JavaMelodyLogger} pour Log4J.
26  * @author Emeric Vernat
27  */

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