KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > logging > JetspeedLogger


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

17
18 // Log4J classes
19
import org.apache.log4j.Level;
20 import org.apache.log4j.LogManager;
21 import org.apache.log4j.Logger;
22
23 /**
24  * The implementation of loggers for Jetspeed.
25  *
26  * This class acts as a wrapper so that the underlying logging implementation
27  * is hidden fromthe rest of Jetspeed
28  * The current implementation uses Log4J.
29  *
30  * @author <a HREF="mailto:harald@ommang.com">Harald Ommang</a>
31  */

32 public class JetspeedLogger
33 {
34  
35     /**
36      * The Log4J logger that is wrapped
37      */

38     private Logger logger;
39
40     /**
41      * Constructor. Initialises this class with a given logger.
42      * If the logger is null, one is given named from this class.
43      *
44      * @param logger The logger to wrap
45      */

46     public JetspeedLogger(Logger logger)
47     {
48         if(logger != null)
49         {
50             this.logger = logger;
51         } else
52         {
53             this.logger = LogManager.getLogger(JetspeedLogger.class.getName());
54         }
55     }
56
57     /**
58      * Checks if the current logger is enabled for debug logging.
59      *
60      * @return true if debug is enabled
61      */

62     public boolean isDebugEnabled()
63     {
64         return logger.isDebugEnabled();
65     }
66
67     /**
68      * Checks if the current logger is enabled for error logging.
69      *
70      * @return true if error is enabled
71      */

72     public boolean isErrorEnabled()
73     {
74         return logger.isEnabledFor(Level.ERROR);
75     }
76
77     /**
78      * Checks if the current logger is enabled for fatal logging.
79      *
80      * @return true if fatal is enabled
81      */

82     public boolean isFatalEnabled()
83     {
84         return logger.isEnabledFor(Level.FATAL);
85     }
86
87     /**
88      * Checks if the current logger is enabled for info logging.
89      *
90      * @return true if info is enabled
91      */

92     public boolean isInfoEnabled()
93     {
94         return logger.isInfoEnabled();
95     }
96
97     /**
98      * Checks if the current logger is enabled for trace logging.
99      * Wtih log4J, this is the same as debug.
100      *
101      * @return true if trace is enabled
102      */

103     public boolean isTraceEnabled()
104     {
105         return logger.isDebugEnabled();
106     }
107
108     /**
109      * Checks if the current logger is enabled for warning logging.
110      *
111      * @return true if warning is enabled
112      */

113     public boolean isWarnEnabled()
114     {
115         return logger.isEnabledFor(Level.WARN);
116     }
117
118     /**
119      * Logs the given object if debug is enabled
120      *
121      * @param obj Object to log
122      */

123     public void debug(Object JavaDoc obj)
124     {
125         logger.debug(obj);
126     }
127
128     /**
129      * Logs the given object and throwable if debug is enabled
130      *
131      * @param obj Object to log
132      * @param throwable The underlying implementation may log stack trace for this
133      */

134     public void debug(Object JavaDoc obj, Throwable JavaDoc throwable)
135     {
136         logger.debug(obj, throwable);
137     }
138
139     /**
140      * Logs the given object if error is enabled
141      *
142      * @param obj Object to log
143      */

144     public void error(Object JavaDoc obj)
145     {
146         logger.error(obj);
147     }
148
149     /**
150      * Logs the given object and throwable if error is enabled
151      *
152      * @param obj Object to log
153      * @param throwable The underlying implementation may log stack trace for this
154      */

155     public void error(Object JavaDoc obj, Throwable JavaDoc throwable)
156     {
157         logger.error(obj, throwable);
158     }
159
160     /**
161      * Logs the given object if fatal is enabled
162      *
163      * @param obj Object to log
164      */

165     public void fatal(Object JavaDoc obj)
166     {
167         logger.fatal(obj);
168     }
169
170     /**
171      * Logs the given object and throwable if fatal is enabled
172      *
173      * @param obj Object to log
174      * @param throwable The underlying implementation may log stack trace for this
175      */

176     public void fatal(Object JavaDoc obj, Throwable JavaDoc throwable)
177     {
178         logger.fatal(obj, throwable);
179     }
180
181     /**
182      * Logs the given object if info is enabled
183      *
184      * @param obj Object to log
185      */

186     public void info(Object JavaDoc obj)
187     {
188         logger.info(obj);
189     }
190
191     /**
192      * Logs the given object and throwable if info is enabled
193      *
194      * @param obj Object to log
195      * @param throwable The underlying implementation may log stack trace for this
196      */

197     public void info(Object JavaDoc obj, Throwable JavaDoc throwable)
198     {
199         logger.info(obj, throwable);
200     }
201
202     /**
203      * Logs the given object if trace is enabled
204      * With Log4J, this is the same as debug
205      *
206      * @param obj Object to log
207      */

208     public void trace(Object JavaDoc obj)
209     {
210         logger.debug(obj);
211     }
212
213     /**
214      * Logs the given object and throwable if trace is enabled
215      * With Log4J, this is the same as debug
216      *
217      * @param obj Object to log
218      * @param throwable The underlying implementation may log stack trace for this
219      */

220     public void trace(Object JavaDoc obj, Throwable JavaDoc throwable)
221     {
222         logger.debug(obj, throwable);
223     }
224
225     /**
226      * Logs the given object if warning is enabled
227      *
228      * @param obj Object to log
229      */

230     public void warn(Object JavaDoc obj)
231     {
232         logger.warn(obj);
233     }
234
235     /**
236      * Logs the given object and throwable if warning is enabled
237      *
238      * @param obj Object to log
239      * @param throwable The underlying implementation may log stack trace for this
240      */

241     public void warn(Object JavaDoc obj, Throwable JavaDoc throwable)
242     {
243         logger.warn(obj, throwable);
244     }
245 } // class JetspeedLogger
246

247
Popular Tags