001: /*
002: * Copyright (C) The DNA Group. All rights reserved.
003: *
004: * This software is published under the terms of the DNA
005: * Software License version 1.1, a copy of which has been included
006: * with this distribution in the LICENSE.txt file.
007: */
008: package org.codehaus.dna.impl;
009:
010: import java.util.logging.Level;
011:
012: import org.codehaus.dna.Logger;
013:
014: /**
015: * Logging facade implmentation for JDK1.4 logging toolkit.
016: * The following lists the mapping between DNA log levels
017: * and JDK1.4 log levels.
018: *
019: * <ul>
020: * <li>trace ==> finest</li>
021: * <li>debug ==> fine</li>
022: * <li>info ==> info</li>
023: * <li>warn ==> warning</li>
024: * <li>error ==> severe</li>
025: * </ul>
026: *
027: * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
028: */
029: public class Jdk14Logger implements Logger {
030: /**
031: * The JDK1.4 logger.
032: */
033: private final java.util.logging.Logger m_logger;
034:
035: /**
036: * Create an instance of JDK14Logger facade.
037: *
038: * @param logger the JDK1.4 logger.
039: */
040: public Jdk14Logger(final java.util.logging.Logger logger) {
041: if (null == logger) {
042: throw new NullPointerException("logger");
043: }
044: m_logger = logger;
045: }
046:
047: /**
048: * Log a trace message.
049: *
050: * @param message the message
051: */
052: public void trace(final String message) {
053: m_logger.log(Level.FINEST, message);
054: }
055:
056: /**
057: * Log a trace message with an associated throwable.
058: *
059: * @param message the message
060: * @param throwable the throwable
061: */
062: public void trace(final String message, final Throwable throwable) {
063: m_logger.log(Level.FINEST, message, throwable);
064: }
065:
066: /**
067: * Return true if a trace message will be logged.
068: *
069: * @return true if message will be logged
070: */
071: public boolean isTraceEnabled() {
072: return m_logger.isLoggable(Level.FINEST);
073: }
074:
075: /**
076: * Log a debug message.
077: *
078: * @param message the message
079: */
080: public void debug(final String message) {
081: m_logger.log(Level.FINE, message);
082: }
083:
084: /**
085: * Log a debug message with an associated throwable.
086: *
087: * @param message the message
088: * @param throwable the throwable
089: */
090: public void debug(final String message, final Throwable throwable) {
091: m_logger.log(Level.FINE, message, throwable);
092: }
093:
094: /**
095: * Return true if a debug message will be logged.
096: *
097: * @return true if message will be logged
098: */
099: public boolean isDebugEnabled() {
100: return m_logger.isLoggable(Level.FINE);
101: }
102:
103: /**
104: * Log a info message.
105: *
106: * @param message the message
107: */
108: public void info(final String message) {
109: m_logger.log(Level.INFO, message);
110: }
111:
112: /**
113: * Log a info message with an associated throwable.
114: *
115: * @param message the message
116: * @param throwable the throwable
117: */
118: public void info(final String message, final Throwable throwable) {
119: m_logger.log(Level.INFO, message, throwable);
120: }
121:
122: /**
123: * Return true if an info message will be logged.
124: *
125: * @return true if message will be logged
126: */
127: public boolean isInfoEnabled() {
128: return m_logger.isLoggable(Level.INFO);
129: }
130:
131: /**
132: * Log a warn message.
133: *
134: * @param message the message
135: */
136: public void warn(final String message) {
137: m_logger.log(Level.WARNING, message);
138: }
139:
140: /**
141: * Log a warn message with an associated throwable.
142: *
143: * @param message the message
144: * @param throwable the throwable
145: */
146: public void warn(final String message, final Throwable throwable) {
147: m_logger.log(Level.WARNING, message, throwable);
148: }
149:
150: /**
151: * Return true if a warn message will be logged.
152: *
153: * @return true if message will be logged
154: */
155: public boolean isWarnEnabled() {
156: return m_logger.isLoggable(Level.WARNING);
157: }
158:
159: /**
160: * Log a error message.
161: *
162: * @param message the message
163: */
164: public void error(final String message) {
165: m_logger.log(Level.SEVERE, message);
166: }
167:
168: /**
169: * Log a error message with an associated throwable.
170: *
171: * @param message the message
172: * @param throwable the throwable
173: */
174: public void error(final String message, final Throwable throwable) {
175: m_logger.log(Level.SEVERE, message, throwable);
176: }
177:
178: /**
179: * Return true if a error message will be logged.
180: *
181: * @return true if message will be logged
182: */
183: public boolean isErrorEnabled() {
184: return m_logger.isLoggable(Level.SEVERE);
185: }
186:
187: /**
188: * Get the child logger with specified name.
189: *
190: * @param name the name of child logger
191: * @return the child logger
192: */
193: public Logger getChildLogger(final String name) {
194: final String childName = m_logger.getName() + "." + name;
195: return new Jdk14Logger(java.util.logging.Logger
196: .getLogger(childName));
197: }
198: }
|