KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > codehaus > dna > impl > Jdk14Logger


1 /*
2  * Copyright (C) The DNA Group. All rights reserved.
3  *
4  * This software is published under the terms of the DNA
5  * Software License version 1.1, a copy of which has been included
6  * with this distribution in the LICENSE.txt file.
7  */

8 package org.codehaus.dna.impl;
9
10 import java.util.logging.Level JavaDoc;
11
12 import org.codehaus.dna.Logger;
13
14 /**
15  * Logging facade implmentation for JDK1.4 logging toolkit.
16  * The following lists the mapping between DNA log levels
17  * and JDK1.4 log levels.
18  *
19  * <ul>
20  * <li>trace ==&gt; finest</li>
21  * <li>debug ==&gt; fine</li>
22  * <li>info ==&gt; info</li>
23  * <li>warn ==&gt; warning</li>
24  * <li>error ==&gt; severe</li>
25  * </ul>
26  *
27  * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
28  */

29 public class Jdk14Logger
30     implements Logger
31 {
32     /**
33      * The JDK1.4 logger.
34      */

35     private final java.util.logging.Logger JavaDoc m_logger;
36
37     /**
38      * Create an instance of JDK14Logger facade.
39      *
40      * @param logger the JDK1.4 logger.
41      */

42     public Jdk14Logger( final java.util.logging.Logger JavaDoc logger )
43     {
44         if( null == logger )
45         {
46             throw new NullPointerException JavaDoc( "logger" );
47         }
48         m_logger = logger;
49     }
50
51     /**
52      * Log a trace message.
53      *
54      * @param message the message
55      */

56     public void trace( final String JavaDoc message )
57     {
58         m_logger.log( Level.FINEST, message );
59     }
60
61     /**
62      * Log a trace message with an associated throwable.
63      *
64      * @param message the message
65      * @param throwable the throwable
66      */

67     public void trace( final String JavaDoc message,
68                        final Throwable JavaDoc throwable )
69     {
70         m_logger.log( Level.FINEST, message, throwable );
71     }
72
73     /**
74      * Return true if a trace message will be logged.
75      *
76      * @return true if message will be logged
77      */

78     public boolean isTraceEnabled()
79     {
80         return m_logger.isLoggable( Level.FINEST );
81     }
82
83     /**
84      * Log a debug message.
85      *
86      * @param message the message
87      */

88     public void debug( final String JavaDoc message )
89     {
90         m_logger.log( Level.FINE, message );
91     }
92
93     /**
94      * Log a debug message with an associated throwable.
95      *
96      * @param message the message
97      * @param throwable the throwable
98      */

99     public void debug( final String JavaDoc message,
100                        final Throwable JavaDoc throwable )
101     {
102         m_logger.log( Level.FINE, message, throwable );
103     }
104
105     /**
106      * Return true if a debug message will be logged.
107      *
108      * @return true if message will be logged
109      */

110     public boolean isDebugEnabled()
111     {
112         return m_logger.isLoggable( Level.FINE );
113     }
114
115     /**
116      * Log a info message.
117      *
118      * @param message the message
119      */

120     public void info( final String JavaDoc message )
121     {
122         m_logger.log( Level.INFO, message );
123     }
124
125     /**
126      * Log a info message with an associated throwable.
127      *
128      * @param message the message
129      * @param throwable the throwable
130      */

131     public void info( final String JavaDoc message,
132                       final Throwable JavaDoc throwable )
133     {
134         m_logger.log( Level.INFO, message, throwable );
135     }
136
137     /**
138      * Return true if an info message will be logged.
139      *
140      * @return true if message will be logged
141      */

142     public boolean isInfoEnabled()
143     {
144         return m_logger.isLoggable( Level.INFO );
145     }
146
147     /**
148      * Log a warn message.
149      *
150      * @param message the message
151      */

152     public void warn( final String JavaDoc message )
153     {
154         m_logger.log( Level.WARNING, message );
155     }
156
157     /**
158      * Log a warn message with an associated throwable.
159      *
160      * @param message the message
161      * @param throwable the throwable
162      */

163     public void warn( final String JavaDoc message,
164                       final Throwable JavaDoc throwable )
165     {
166         m_logger.log( Level.WARNING, message, throwable );
167     }
168
169     /**
170      * Return true if a warn message will be logged.
171      *
172      * @return true if message will be logged
173      */

174     public boolean isWarnEnabled()
175     {
176         return m_logger.isLoggable( Level.WARNING );
177     }
178
179     /**
180      * Log a error message.
181      *
182      * @param message the message
183      */

184     public void error( final String JavaDoc message )
185     {
186         m_logger.log( Level.SEVERE, message );
187     }
188
189     /**
190      * Log a error message with an associated throwable.
191      *
192      * @param message the message
193      * @param throwable the throwable
194      */

195     public void error( final String JavaDoc message,
196                        final Throwable JavaDoc throwable )
197     {
198         m_logger.log( Level.SEVERE, message, throwable );
199     }
200
201     /**
202      * Return true if a error message will be logged.
203      *
204      * @return true if message will be logged
205      */

206     public boolean isErrorEnabled()
207     {
208         return m_logger.isLoggable( Level.SEVERE );
209     }
210
211     /**
212      * Get the child logger with specified name.
213      *
214      * @param name the name of child logger
215      * @return the child logger
216      */

217     public Logger getChildLogger( final String JavaDoc name )
218     {
219         final String JavaDoc childName = m_logger.getName() + "." + name;
220         return new Jdk14Logger( java.util.logging.
221                                 Logger.getLogger( childName ) );
222     }
223 }
224
Popular Tags