View Javadoc

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.util.logging.Level;
20  import java.util.logging.Logger;
21  
22  /**
23   * The facade to the JDK logger.
24   *
25   * @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/JDKLogger.java $
26   *
27   * @author Jonas Hauenstein (JHN)
28   */
29  public class JDKLogger extends GenericLogger {
30  	
31  	/**
32  	 * The JDK Logger.
33  	 */
34  	private Logger m_l;
35  	
36  	/**
37  	 * Constructor.
38  	 * This GenericLogger is using the JDK Logger for logging.
39  	 *
40  	 * @param name The name of the logger
41  	 */
42  	public JDKLogger(String name) {
43  		super(null);
44  		m_l = Logger.getLogger(name);
45  		m_logLevels.put("debug", m_l.isLoggable(Level.FINEST));
46  		m_logLevels.put("error", m_l.isLoggable(Level.SEVERE));
47  		m_logLevels.put("info", m_l.isLoggable(Level.INFO));
48  		m_logLevels.put("trace", m_l.isLoggable(Level.FINE));
49  		m_logLevels.put("warn", m_l.isLoggable(Level.WARNING));
50  	}
51  	
52  	/** {@inheritDoc} */
53  	public void log(String level, String msg) {
54  		if (m_l != null && m_logLevels.containsKey(level) && m_logLevels.get(level)) {
55  			//translate levels to jdk logger levels
56  			if (level.equals("info")) {
57  				m_l.info(msg);
58  			} else if (level.equals("warn")) {
59  				m_l.warning(msg);
60  			} else if (level.equals("error")) {
61  				m_l.severe(msg);
62  			} else if (level.equals("trace")) {
63  				m_l.fine(msg);
64  			} else if (level.equals("debug")) {
65  				m_l.finest(msg);
66  			}
67  		}
68  	}
69  	
70  }