KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > logging > impl > Log4JCategoryLog


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

16
17
18 package org.apache.commons.logging.impl;
19
20 import org.apache.commons.logging.Log;
21 import org.apache.log4j.Category;
22 import org.apache.log4j.Priority;
23
24 /**
25  * <p>Implementation of {@link Log} that maps directly to a Log4J
26  * <strong>Category</strong>. Initial configuration of the corresponding
27  * Category instances should be done in the usual manner, as outlined in
28  * the Log4J documentation.</p>
29  *
30  * @deprecated Use {@link Log4JLogger} instead.
31  *
32  * @author <a HREF="mailto:sanders@apache.org">Scott Sanders</a>
33  * @author Rod Waldhoff
34  * @author Robert Burrell Donkin
35  * @version $Id: Log4JCategoryLog.java,v 1.15 2004/02/28 21:46:45 craigmcc Exp $
36  */

37 public final class Log4JCategoryLog implements Log {
38
39
40     // ------------------------------------------------------------- Attributes
41

42     /** The fully qualified name of the Log4JCategoryLog class. */
43     private static final String JavaDoc FQCN = Log4JCategoryLog.class.getName();
44
45     /** Log to this category */
46     private Category category = null;
47
48
49     // ------------------------------------------------------------ Constructor
50

51     public Log4JCategoryLog() {
52     }
53
54
55     /**
56      * Base constructor.
57      */

58     public Log4JCategoryLog(String JavaDoc name) {
59         this.category=Category.getInstance(name);
60     }
61
62     /** For use with a log4j factory.
63      */

64     public Log4JCategoryLog(Category category ) {
65         this.category=category;
66     }
67
68
69     // ---------------------------------------------------------- Implmentation
70

71
72     /**
73      * Log a message to the Log4j Category with <code>TRACE</code> priority.
74      * Currently logs to <code>DEBUG</code> level in Log4J.
75      */

76     public void trace(Object JavaDoc message) {
77         category.log(FQCN, Priority.DEBUG, message, null);
78     }
79
80
81     /**
82      * Log an error to the Log4j Category with <code>TRACE</code> priority.
83      * Currently logs to <code>DEBUG</code> level in Log4J.
84      */

85     public void trace(Object JavaDoc message, Throwable JavaDoc t) {
86         category.log(FQCN, Priority.DEBUG, message, t );
87     }
88
89
90     /**
91      * Log a message to the Log4j Category with <code>DEBUG</code> priority.
92      */

93     public void debug(Object JavaDoc message) {
94         category.log(FQCN, Priority.DEBUG, message, null);
95     }
96
97     /**
98      * Log an error to the Log4j Category with <code>DEBUG</code> priority.
99      */

100     public void debug(Object JavaDoc message, Throwable JavaDoc t) {
101         category.log(FQCN, Priority.DEBUG, message, t );
102     }
103
104
105     /**
106      * Log a message to the Log4j Category with <code>INFO</code> priority.
107      */

108     public void info(Object JavaDoc message) {
109         category.log(FQCN, Priority.INFO, message, null );
110     }
111
112
113     /**
114      * Log an error to the Log4j Category with <code>INFO</code> priority.
115      */

116     public void info(Object JavaDoc message, Throwable JavaDoc t) {
117         category.log(FQCN, Priority.INFO, message, t );
118     }
119
120
121     /**
122      * Log a message to the Log4j Category with <code>WARN</code> priority.
123      */

124     public void warn(Object JavaDoc message) {
125         category.log(FQCN, Priority.WARN, message, null );
126     }
127
128
129     /**
130      * Log an error to the Log4j Category with <code>WARN</code> priority.
131      */

132     public void warn(Object JavaDoc message, Throwable JavaDoc t) {
133         category.log(FQCN, Priority.WARN, message, t );
134     }
135
136
137     /**
138      * Log a message to the Log4j Category with <code>ERROR</code> priority.
139      */

140     public void error(Object JavaDoc message) {
141         category.log(FQCN, Priority.ERROR, message, null );
142     }
143
144
145     /**
146      * Log an error to the Log4j Category with <code>ERROR</code> priority.
147      */

148     public void error(Object JavaDoc message, Throwable JavaDoc t) {
149         category.log(FQCN, Priority.ERROR, message, t );
150     }
151
152
153     /**
154      * Log a message to the Log4j Category with <code>FATAL</code> priority.
155      */

156     public void fatal(Object JavaDoc message) {
157         category.log(FQCN, Priority.FATAL, message, null );
158     }
159
160
161     /**
162      * Log an error to the Log4j Category with <code>FATAL</code> priority.
163      */

164     public void fatal(Object JavaDoc message, Throwable JavaDoc t) {
165         category.log(FQCN, Priority.FATAL, message, t );
166     }
167
168
169     /**
170      * Return the native Category instance we are using.
171      */

172     public Category getCategory() {
173         return (this.category);
174     }
175
176
177     /**
178      * Check whether the Log4j Category used is enabled for <code>DEBUG</code> priority.
179      */

180     public boolean isDebugEnabled() {
181         return category.isDebugEnabled();
182     }
183
184
185      /**
186      * Check whether the Log4j Category used is enabled for <code>ERROR</code> priority.
187      */

188     public boolean isErrorEnabled() {
189         return category.isEnabledFor(Priority.ERROR);
190     }
191
192
193     /**
194      * Check whether the Log4j Category used is enabled for <code>FATAL</code> priority.
195      */

196     public boolean isFatalEnabled() {
197         return category.isEnabledFor(Priority.FATAL);
198     }
199
200
201     /**
202      * Check whether the Log4j Category used is enabled for <code>INFO</code> priority.
203      */

204     public boolean isInfoEnabled() {
205         return category.isInfoEnabled();
206     }
207
208
209     /**
210      * Check whether the Log4j Category used is enabled for <code>TRACE</code> priority.
211      * For Log4J, this returns the value of <code>isDebugEnabled()</code>
212      */

213     public boolean isTraceEnabled() {
214         return category.isDebugEnabled();
215     }
216
217     /**
218      * Check whether the Log4j Category used is enabled for <code>WARN</code> priority.
219      */

220     public boolean isWarnEnabled() {
221         return category.isEnabledFor(Priority.WARN);
222     }
223 }
224
Popular Tags