KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > logging > log4j > Log4JLogger


1 /*
2  * Copyright 2004 Apache Software Foundation
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
12  * implied.
13  *
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.avalon.logging.log4j;
19
20 import org.apache.avalon.framework.logger.Logger;
21
22 import org.apache.log4j.Level;
23
24 /**
25  * Implementation of the Avalon Logger interface using the Log4J
26  * implementation strategy.
27  *
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  * @version $Revision: 1.2 $
30  */

31 public class Log4JLogger
32     implements Logger
33 {
34     private org.apache.log4j.Logger m_Logger;
35     
36     Log4JLogger( org.apache.log4j.Logger log4jLogger )
37     {
38         m_Logger = log4jLogger;
39     }
40     
41     /**
42      * Log a debug message.
43      *
44      * @param message the message
45      */

46     public void debug( String JavaDoc message )
47     {
48         m_Logger.debug( message );
49     }
50
51     /**
52      * Log a debug message.
53      *
54      * @param message the message
55      * @param throwable the throwable
56      */

57     public void debug( String JavaDoc message, Throwable JavaDoc throwable )
58     {
59         m_Logger.debug( message, throwable );
60     }
61
62     /**
63      * Determine if messages of priority "debug" will be logged.
64      *
65      * @return true if "debug" messages will be logged
66      */

67     public boolean isDebugEnabled()
68     {
69         return m_Logger.isDebugEnabled();
70     }
71
72     /**
73      * Log a info message.
74      *
75      * @param message the message
76      */

77     public void info( String JavaDoc message )
78     {
79         m_Logger.info( message );
80     }
81
82     /**
83      * Log a info message.
84      *
85      * @param message the message
86      * @param throwable the throwable
87      */

88     public void info( String JavaDoc message, Throwable JavaDoc throwable )
89     {
90         m_Logger.info( message, throwable );
91     }
92
93     /**
94      * Determine if messages of priority "info" will be logged.
95      *
96      * @return true if "info" messages will be logged
97      */

98     public boolean isInfoEnabled()
99     {
100         return m_Logger.isInfoEnabled();
101     }
102
103     /**
104      * Log a warn message.
105      *
106      * @param message the message
107      */

108     public void warn( String JavaDoc message )
109     {
110         m_Logger.warn( message );
111     }
112
113     /**
114      * Log a warn message.
115      *
116      * @param message the message
117      * @param throwable the throwable
118      */

119     public void warn( String JavaDoc message, Throwable JavaDoc throwable )
120     {
121         m_Logger.warn( message, throwable );
122     }
123
124     /**
125      * Determine if messages of priority "warn" will be logged.
126      *
127      * @return true if "warn" messages will be logged
128      */

129     public boolean isWarnEnabled()
130     {
131         return m_Logger.isEnabledFor( Level.WARN );
132     }
133
134     /**
135      * Log a error message.
136      *
137      * @param message the message
138      */

139     public void error( String JavaDoc message )
140     {
141         m_Logger.error( message );
142     }
143
144     /**
145      * Log a error message.
146      *
147      * @param message the message
148      * @param throwable the throwable
149      */

150     public void error( String JavaDoc message, Throwable JavaDoc throwable )
151     {
152         m_Logger.error( message, throwable );
153     }
154
155     /**
156      * Determine if messages of priority "error" will be logged.
157      *
158      * @return true if "error" messages will be logged
159      */

160     public boolean isErrorEnabled()
161     {
162         return m_Logger.isEnabledFor( Level.ERROR );
163     }
164
165     /**
166      * Log a fatalError message.
167      *
168      * @param message the message
169      */

170     public void fatalError( String JavaDoc message )
171     {
172         m_Logger.fatal( message );
173     }
174
175     /**
176      * Log a fatalError message.
177      *
178      * @param message the message
179      * @param throwable the throwable
180      */

181     public void fatalError( String JavaDoc message, Throwable JavaDoc throwable )
182     {
183         m_Logger.fatal( message, throwable );
184     }
185
186     /**
187      * Determine if messages of priority "fatalError" will be logged.
188      *
189      * @return true if "fatalError" messages will be logged
190      */

191     public boolean isFatalErrorEnabled()
192     {
193         return m_Logger.isEnabledFor( Level.FATAL );
194     }
195
196     /**
197      * Create a new child logger.
198      * The name of the child logger is [current-loggers-name].[passed-in-name]
199      * Throws <code>IllegalArgumentException</code> if name has an empty element name
200      *
201      * @param name the subname of this logger
202      * @return the new logger
203      */

204     public Logger getChildLogger( String JavaDoc name )
205     {
206         String JavaDoc newName = m_Logger.getName() + "." + name;
207         org.apache.log4j.Logger childLog4JLogger =
208             org.apache.log4j.Logger.getLogger( newName );
209         Log4JLogger child = new Log4JLogger( childLog4JLogger );
210         return child;
211     }
212 }
213
Popular Tags