KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > framework > logger > CommonsLogger


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. 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 package org.apache.avalon.framework.logger;
18
19 import org.apache.avalon.framework.logger.Logger;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23
24 /**
25  * An Avalon {@link Logger} implementation backed by a {@plaintext Log logger}
26  * of commons lLogging.
27  *
28  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
29  * @version $Id: CommonsLogger.java 506231 2007-02-12 02:36:54Z crossley $
30  * @since 4.3
31  */

32 public class CommonsLogger implements Logger {
33
34     private final Log log;
35     private final String JavaDoc name;
36
37     /**
38      * Construct a CommonsLogger. The constructor needs explicitly the name of the
39      * commons-logger, since the commons-logging API misses the functionality to
40      * retrieve it from the logger instance.
41      *
42      * @param log The logger of commons-logging.
43      * @param name The name of the logger.
44      * @since 2.0
45      */

46     public CommonsLogger(final Log log, final String JavaDoc name)
47     {
48         this.log = log;
49         this.name = name;
50     }
51
52     /**
53      * @see org.apache.avalon.framework.logger.Logger#debug(java.lang.String)
54      */

55     public void debug(final String JavaDoc message)
56     {
57         this.log.debug(message);
58     }
59
60     /**
61      * @see org.apache.avalon.framework.logger.Logger#debug(java.lang.String, java.lang.Throwable)
62      */

63     public void debug(final String JavaDoc message, final Throwable JavaDoc throwable)
64     {
65         this.log.debug(message, throwable);
66     }
67
68     /**
69      * @see org.apache.avalon.framework.logger.Logger#isDebugEnabled()
70      */

71     public boolean isDebugEnabled()
72     {
73         return this.log.isDebugEnabled();
74     }
75
76     /**
77      * @see org.apache.avalon.framework.logger.Logger#info(java.lang.String)
78      */

79     public void info(final String JavaDoc message)
80     {
81         this.log.info(message);
82     }
83
84     /**
85      * @see org.apache.avalon.framework.logger.Logger#info(java.lang.String, java.lang.Throwable)
86      */

87     public void info(final String JavaDoc message, final Throwable JavaDoc throwable)
88     {
89         this.log.info(message, throwable);
90     }
91
92     /**
93      * @see org.apache.avalon.framework.logger.Logger#isInfoEnabled()
94      */

95     public boolean isInfoEnabled()
96     {
97         return this.log.isInfoEnabled();
98     }
99
100     /**
101      * @see org.apache.avalon.framework.logger.Logger#warn(java.lang.String)
102      */

103     public void warn(final String JavaDoc message)
104     {
105         this.log.warn(message);
106     }
107
108     /**
109      * @see org.apache.avalon.framework.logger.Logger#warn(java.lang.String, java.lang.Throwable)
110      */

111     public void warn(final String JavaDoc message, final Throwable JavaDoc throwable)
112     {
113         this.log.warn(message, throwable);
114     }
115
116     /**
117      * @see org.apache.avalon.framework.logger.Logger#isWarnEnabled()
118      */

119     public boolean isWarnEnabled()
120     {
121         return this.log.isWarnEnabled();
122     }
123
124     /**
125      * @see org.apache.avalon.framework.logger.Logger#error(java.lang.String)
126      */

127     public void error(final String JavaDoc message)
128     {
129         this.log.error(message);
130     }
131
132     /**
133      * @see org.apache.avalon.framework.logger.Logger#error(java.lang.String, java.lang.Throwable)
134      */

135     public void error(final String JavaDoc message, final Throwable JavaDoc throwable)
136     {
137         this.log.error(message, throwable);
138     }
139
140     /**
141      * @see org.apache.avalon.framework.logger.Logger#isErrorEnabled()
142      */

143     public boolean isErrorEnabled()
144     {
145         return this.log.isErrorEnabled();
146     }
147
148     /**
149      * @see org.apache.avalon.framework.logger.Logger#fatalError(java.lang.String)
150      */

151     public void fatalError(final String JavaDoc message)
152     {
153         this.log.fatal(message);
154     }
155
156     /**
157      * @see org.apache.avalon.framework.logger.Logger#fatalError(java.lang.String, java.lang.Throwable)
158      */

159     public void fatalError(final String JavaDoc message, final Throwable JavaDoc throwable)
160     {
161         this.log.fatal(message, throwable);
162     }
163
164     /**
165      * @see org.apache.avalon.framework.logger.Logger#isFatalErrorEnabled()
166      */

167     public boolean isFatalErrorEnabled()
168     {
169         return this.log.isFatalEnabled();
170     }
171
172     /**
173      * @see org.apache.avalon.framework.logger.Logger#getChildLogger(java.lang.String)
174      */

175     public Logger getChildLogger(final String JavaDoc name)
176     {
177         final String JavaDoc newName = this.name + '.' + name;
178         return new CommonsLogger(LogFactory.getLog(newName), newName);
179     }
180 }
181
Popular Tags