KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > logicalcobwebs > logging > impl > LogKitLogger


1 /*
2  * $Header: /cvsroot/proxool/proxool/src/java/org/logicalcobwebs/logging/impl/LogKitLogger.java,v 1.2 2003/02/08 14:27:51 chr32 Exp $
3  * $Revision: 1.2 $
4  * $Date: 2003/02/08 14:27:51 $
5  *
6  * ====================================================================
7  *
8  * The Apache Software License, Version 1.1
9  *
10  * Copyright (c) 1999-2002 The Apache Software Foundation. All rights
11  * reserved.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  *
17  * 1. Redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer.
19  *
20  * 2. Redistributions in binary form must reproduce the above copyright
21  * notice, this list of conditions and the following disclaimer in
22  * the documentation and/or other materials provided with the
23  * distribution.
24  *
25  * 3. The end-user documentation included with the redistribution, if
26  * any, must include the following acknowlegement:
27  * "This product includes software developed by the
28  * Apache Software Foundation (http://www.apache.org/)."
29  * Alternately, this acknowlegement may appear in the software itself,
30  * if and wherever such third-party acknowlegements normally appear.
31  *
32  * 4. The names "The Jakarta Project", "Commons", and "Apache Software
33  * Foundation" must not be used to endorse or promote products derived
34  * from this software without prior written permission. For written
35  * permission, please contact apache@apache.org.
36  *
37  * 5. Products derived from this software may not be called "Apache"
38  * nor may "Apache" appear in their names without prior written
39  * permission of the Apache Group.
40  *
41  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
42  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
43  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
44  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
45  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
47  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
48  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
49  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
50  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
51  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
52  * SUCH DAMAGE.
53  * ====================================================================
54  *
55  * This software consists of voluntary contributions made by many
56  * individuals on behalf of the Apache Software Foundation. For more
57  * information on the Apache Software Foundation, please see
58  * <http://www.apache.org/>.
59  *
60  */

61
62 package org.logicalcobwebs.logging.impl;
63
64 import org.apache.log.Hierarchy;
65 import org.apache.log.Logger;
66 import org.logicalcobwebs.logging.Log;
67
68 /**
69  * <p>Implementation of <code>org.logicalcobwebs.logging.Log</code>
70  * that wraps the <a HREF="http://jakarta.apache.org/avalon/logkit/">jakarta-avalon-logkit</a>
71  * logging system. Configuration of <code>LogKit</code> is left to the user.</p>
72  *
73  * <p><code>LogKit</code> accepts only <code>String</code> messages.
74  * Therefore, this implementation converts object messages into strings
75  * by called their <code>toString()</code> method before logging them.</p>
76  *
77  * @author <a HREF="mailto:sanders@apache.org">Scott Sanders</a>
78  * @author Robert Burrell Donkin *
79  * @version $Id: LogKitLogger.java,v 1.2 2003/02/08 14:27:51 chr32 Exp $
80  */

81
82 public final class LogKitLogger implements Log {
83
84     // ------------------------------------------------------------- Attributes
85

86
87     /** Logging goes to this <code>LogKit</code> logger */
88     private Logger logger = null;
89
90
91     // ------------------------------------------------------------ Constructor
92

93
94     /**
95      * Construct <code>LogKitLogger</code> which wraps the <code>LogKit</code>
96      * logger with given name.
97      *
98      * @param name log name
99      */

100     public LogKitLogger (String JavaDoc name) {
101         logger = Hierarchy.getDefaultHierarchy ().getLoggerFor (name);
102     }
103
104
105     // ----------------------------------------------------- Log Implementation
106

107
108     /**
109      * Log message to <code>LogKit</code> logger with <code>DEBUG</code> priority.
110      */

111     public void trace (Object JavaDoc message) {
112         debug (message);
113     }
114
115     /**
116      * Log error to <code>LogKit</code> logger with <code>DEBUG</code> priority.
117      */

118     public void trace (Object JavaDoc message, Throwable JavaDoc t) {
119         debug (message, t);
120     }
121
122     /**
123      * Log message to <code>LogKit</code> logger with <code>DEBUG</code> priority.
124      */

125     public void debug (Object JavaDoc message) {
126         if (message != null) {
127             logger.debug (String.valueOf (message));
128         }
129     }
130
131     /**
132      * Log error to <code>LogKit</code> logger with <code>DEBUG</code> priority.
133      */

134     public void debug (Object JavaDoc message, Throwable JavaDoc t) {
135         if (message != null) {
136             logger.debug (String.valueOf (message), t);
137         }
138     }
139
140     /**
141      * Log message to <code>LogKit</code> logger with <code>INFO</code> priority.
142      */

143     public void info (Object JavaDoc message) {
144         if (message != null) {
145             logger.info (String.valueOf (message));
146         }
147     }
148
149     /**
150      * Log error to <code>LogKit</code> logger with <code>INFO</code> priority.
151      */

152     public void info (Object JavaDoc message, Throwable JavaDoc t) {
153         if (message != null) {
154             logger.info (String.valueOf (message), t);
155         }
156     }
157
158     /**
159      * Log message to <code>LogKit</code> logger with <code>WARN</code> priority.
160      */

161     public void warn (Object JavaDoc message) {
162         if (message != null) {
163             logger.warn (String.valueOf (message));
164         }
165     }
166
167     /**
168      * Log error to <code>LogKit</code> logger with <code>WARN</code> priority.
169      */

170     public void warn (Object JavaDoc message, Throwable JavaDoc t) {
171         if (message != null) {
172             logger.warn (String.valueOf (message), t);
173         }
174     }
175
176     /**
177      * Log message to <code>LogKit</code> logger with <code>ERROR</code> priority.
178      */

179     public void error (Object JavaDoc message) {
180         if (message != null) {
181             logger.error (String.valueOf (message));
182         }
183     }
184
185     /**
186      * Log error to <code>LogKit</code> logger with <code>ERROR</code> priority.
187      */

188     public void error (Object JavaDoc message, Throwable JavaDoc t) {
189         if (message != null) {
190             logger.error (String.valueOf (message), t);
191         }
192     }
193
194     /**
195      * Log message to <code>LogKit</code> logger with <code>FATAL_ERROR</code> priority.
196      */

197     public void fatal (Object JavaDoc message) {
198         if (message != null) {
199             logger.fatalError (String.valueOf (message));
200         }
201     }
202
203     /**
204      * Log error to <code>LogKit</code> logger with <code>FATAL_ERROR</code> priority.
205      */

206     public void fatal (Object JavaDoc message, Throwable JavaDoc t) {
207         if (message != null) {
208             logger.fatalError (String.valueOf (message), t);
209         }
210     }
211
212     /**
213      * Check whether the <code>LogKit</code> logger will log messages of priority <code>DEBUG</code>.
214      */

215     public boolean isDebugEnabled () {
216         return logger.isDebugEnabled ();
217     }
218
219     /**
220      * Check whether the <code>LogKit</code> logger will log messages of priority <code>ERROR</code>.
221      */

222     public boolean isErrorEnabled () {
223         return logger.isErrorEnabled ();
224     }
225
226     /**
227      * Check whether the <code>LogKit</code> logger will log messages of priority <code>FATAL_ERROR</code>.
228      */

229     public boolean isFatalEnabled () {
230         return logger.isFatalErrorEnabled ();
231     }
232
233     /**
234      * Check whether the <code>LogKit</code> logger will log messages of priority <code>INFO</code>.
235      */

236     public boolean isInfoEnabled () {
237         return logger.isInfoEnabled ();
238     }
239
240     /**
241      * Check whether the <code>LogKit</code> logger will log messages of priority <code>DEBUG</code>.
242      */

243     public boolean isTraceEnabled () {
244         return logger.isDebugEnabled ();
245     }
246
247     /**
248      * Check whether the <code>LogKit</code> logger will log messages of priority <code>WARN</code>.
249      */

250     public boolean isWarnEnabled () {
251         return logger.isWarnEnabled ();
252     }
253
254 }
255
256
Popular Tags