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 package org.apache.commons.logging.impl;
18
19 import java.io.Serializable;
20
21 import org.apache.commons.logging.Log;
22 import org.slf4j.Logger;
23
24 /**
25 * Implementation of {@link Log org.apache.commons.logging.Log} interface which
26 * delegates all processing to a wrapped {@link Logger org.slf4j.Logger} instance.
27 *
28 * <p>JCL's FATAL and TRACE levels are mapped to ERROR and DEBUG respectively. All
29 * other levels map one to one.
30 *
31 * @author Ceki Gülcü
32 */
33 public class SLF4JLog implements Log, Serializable {
34
35 private static final long serialVersionUID = 680728617011167209L;
36
37 // in both Log4jLogger and Jdk14Logger classes in the original JCL, the
38 // logger instance is transient
39 private transient Logger logger;
40
41 SLF4JLog(Logger logger) {
42 this.logger = logger;
43 }
44
45 /**
46 * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
47 */
48 public boolean isDebugEnabled() {
49 return logger.isDebugEnabled();
50 }
51
52 /**
53 * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
54 */
55 public boolean isErrorEnabled() {
56 return logger.isErrorEnabled();
57 }
58
59 /**
60 * Delegates to the <code>isErrorEnabled<code> method of the wrapped
61 * <code>org.slf4j.Logger</code> instance.
62 */
63 public boolean isFatalEnabled() {
64 return logger.isErrorEnabled();
65 }
66
67 /**
68 * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
69 */
70 public boolean isInfoEnabled() {
71 return logger.isInfoEnabled();
72 }
73
74 /**
75 * Delegates to the <code>isDebugEnabled<code> method of the wrapped
76 * <code>org.slf4j.Logger</code> instance.
77 */
78 public boolean isTraceEnabled() {
79 return logger.isTraceEnabled();
80 }
81
82 /**
83 * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
84 */
85 public boolean isWarnEnabled() {
86 return logger.isWarnEnabled();
87 }
88
89 /**
90 * Converts the input parameter to String and then delegates to
91 * the debug method of the wrapped <code>org.slf4j.Logger</code> instance.
92 *
93 * @param message the message to log. Converted to {@link String}
94 */
95 public void trace(Object message) {
96 logger.trace(String.valueOf(message));
97 }
98
99 /**
100 * Converts the first input parameter to String and then delegates to
101 * the debug method of the wrapped <code>org.slf4j.Logger</code> instance.
102 *
103 * @param message the message to log. Converted to {@link String}
104 * @param t the exception to log
105 */
106 public void trace(Object message, Throwable t) {
107 logger.trace(String.valueOf(message), t);
108 }
109
110 /**
111 * Converts the input parameter to String and then delegates to the wrapped
112 * <code>org.slf4j.Logger</code> instance.
113 *
114 * @param message the message to log. Converted to {@link String}
115 */
116 public void debug(Object message) {
117 logger.debug(String.valueOf(message));
118 }
119
120 /**
121 * Converts the first input parameter to String and then delegates to
122 * the wrapped <code>org.slf4j.Logger</code> instance.
123 *
124 * @param message the message to log. Converted to {@link String}
125 * @param t the exception to log
126 */
127 public void debug(Object message, Throwable t) {
128 logger.debug(String.valueOf(message), t);
129 }
130
131 /**
132 * Converts the input parameter to String and then delegates to the wrapped
133 * <code>org.slf4j.Logger</code> instance.
134 *
135 * @param message the message to log. Converted to {@link String}
136 */
137 public void info(Object message) {
138 logger.info(String.valueOf(message));
139 }
140
141 /**
142 * Converts the first input parameter to String and then delegates to
143 * the wrapped <code>org.slf4j.Logger</code> instance.
144 *
145 * @param message the message to log. Converted to {@link String}
146 * @param t the exception to log
147 */
148 public void info(Object message, Throwable t) {
149 logger.info(String.valueOf(message), t);
150 }
151
152 /**
153 * Converts the input parameter to String and then delegates to the wrapped
154 * <code>org.slf4j.Logger</code> instance.
155 *
156 * @param message the message to log. Converted to {@link String}
157 */
158 public void warn(Object message) {
159 logger.warn(String.valueOf(message));
160 }
161
162 /**
163 * Converts the first input parameter to String and then delegates to
164 * the wrapped <code>org.slf4j.Logger</code> instance.
165 *
166 * @param message the message to log. Converted to {@link String}
167 * @param t the exception to log
168 */
169 public void warn(Object message, Throwable t) {
170 logger.warn(String.valueOf(message), t);
171 }
172
173 /**
174 * Converts the input parameter to String and then delegates to the wrapped
175 * <code>org.slf4j.Logger</code> instance.
176 *
177 * @param message the message to log. Converted to {@link String}
178 */
179 public void error(Object message) {
180 logger.error(String.valueOf(message));
181 }
182
183 /**
184 * Converts the first input parameter to String and then delegates to
185 * the wrapped <code>org.slf4j.Logger</code> instance.
186 *
187 * @param message the message to log. Converted to {@link String}
188 * @param t the exception to log
189 */
190 public void error(Object message, Throwable t) {
191 logger.error(String.valueOf(message), t);
192 }
193
194
195
196 /**
197 * Converts the input parameter to String and then delegates to
198 * the error method of the wrapped <code>org.slf4j.Logger</code> instance.
199 *
200 * @param message the message to log. Converted to {@link String}
201 */
202 public void fatal(Object message) {
203 logger.error(String.valueOf(message));
204 }
205
206 /**
207 * Converts the first input parameter to String and then delegates to
208 * the error method of the wrapped <code>org.slf4j.Logger</code> instance.
209 *
210 * @param message the message to log. Converted to {@link String}
211 * @param t the exception to log
212 */
213 public void fatal(Object message, Throwable t) {
214 logger.error(String.valueOf(message), t);
215 }
216
217 }