1 /*
2 * EL4J, the Extension Library for the J2EE, adds incremental enhancements to
3 * the spring framework, http://el4j.sf.net
4 * Copyright (C) 2009 by ELCA Informatique SA, Av. de la Harpe 22-24,
5 * 1000 Lausanne, Switzerland, http://www.elca.ch
6 *
7 * EL4J is published under the GNU Lesser General Public License (LGPL)
8 * Version 2.1. See http://www.gnu.org/licenses/
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * For alternative licensing, please contact info@elca.ch
16 */
17 package ch.elca.el4j.util.socketstatistics.genericlogger;
18
19 import java.lang.reflect.Method;
20
21 /**
22 * The facade to the Log4J logger.
23 *
24 * @svnLink $Revision: 4093 $;$Date: 2010-01-15 14:26:34 +0100 (Fr, 15. Jan 2010) $;$Author: jonasha $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/socketstatistics/src/main/java/ch/elca/el4j/util/socketstatistics/genericlogger/Log4JLogger.java $
25 *
26 * @author Jonas Hauenstein (JHN)
27 */
28 public class Log4JLogger extends GenericLogger {
29
30 /**
31 * Constructor.
32 * This GenericLogger is using the L4J Logger for logging.
33 *
34 * @param originallogger Reference to the actually used logger for reflective calls
35 */
36 public Log4JLogger(Object originallogger) {
37 super(originallogger);
38 m_logLevels.put("debug", checkForLevel("isDebugEnabled"));
39 m_logLevels.put("error", checkForLevel("isErrorEnabled"));
40 m_logLevels.put("info", checkForLevel("isInfoEnabled"));
41 m_logLevels.put("trace", checkForLevel("isTraceEnabled"));
42 m_logLevels.put("warn", checkForLevel("isWarnEnabled"));
43 }
44
45 /** {@inheritDoc} */
46 public void log(String level, String msg) {
47 if (m_orgLogger != null && m_logLevels.containsKey(level) && m_logLevels.get(level)) {
48 try {
49 Method m = m_orgLogger.getClass().getMethod(level, Object.class);
50 m.invoke(m_orgLogger, msg);
51 } catch (Exception e) { }
52 }
53
54 }
55
56 }