001: // TOTO
002:
003: package org.apache.commons.logging.impl;
004:
005: import java.io.Serializable;
006:
007: import org.apache.commons.logging.Log;
008: import org.slf4j.Logger;
009: import org.slf4j.spi.LocationAwareLogger;
010:
011: /**
012: * Implementation of {@link Log org.apache.commons.logging.Log} interface which
013: * delegates all processing to a wrapped {@link Logger org.slf4j.Logger} instance.
014: *
015: * <p>JCL's FATAL level is mapped to ERROR. All other levels map one to one.
016: *
017: * @author Ceki Gülcü
018: */
019: public class SLF4JLocationAwareLog implements Log, Serializable {
020:
021: private static final long serialVersionUID = -2379157579039314822L;
022:
023: // in both Log4jLogger and Jdk14Logger classes in the original JCL, the
024: // logger instance is transient
025: private transient LocationAwareLogger logger;
026:
027: private static final String FQCN = SLF4JLocationAwareLog.class
028: .getName();
029:
030: SLF4JLocationAwareLog(LocationAwareLogger logger) {
031: this .logger = logger;
032: }
033:
034: /**
035: * Delegates to the <code>isTraceEnabled<code> method of the wrapped
036: * <code>org.slf4j.Logger</code> instance.
037: */
038: public boolean isTraceEnabled() {
039: return logger.isTraceEnabled();
040: }
041:
042: /**
043: * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
044: */
045: public boolean isDebugEnabled() {
046: return logger.isDebugEnabled();
047: }
048:
049: /**
050: * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
051: */
052: public boolean isInfoEnabled() {
053: return logger.isInfoEnabled();
054: }
055:
056: /**
057: * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
058: */
059: public boolean isWarnEnabled() {
060: return logger.isWarnEnabled();
061: }
062:
063: /**
064: * Directly delegates to the wrapped <code>org.slf4j.Logger</code> instance.
065: */
066: public boolean isErrorEnabled() {
067: return logger.isErrorEnabled();
068: }
069:
070: /**
071: * Delegates to the <code>isErrorEnabled<code> method of the wrapped
072: * <code>org.slf4j.Logger</code> instance.
073: */
074: public boolean isFatalEnabled() {
075: return logger.isErrorEnabled();
076: }
077:
078: /**
079: * Converts the input parameter to String and then delegates to
080: * the debug method of the wrapped <code>org.slf4j.Logger</code> instance.
081: *
082: * @param message the message to log. Converted to {@link String}
083: */
084: public void trace(Object message) {
085: logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String
086: .valueOf(message), null);
087: }
088:
089: /**
090: * Converts the first input parameter to String and then delegates to
091: * the debug method of the wrapped <code>org.slf4j.Logger</code> instance.
092: *
093: * @param message the message to log. Converted to {@link String}
094: * @param t the exception to log
095: */
096: public void trace(Object message, Throwable t) {
097: logger.log(null, FQCN, LocationAwareLogger.TRACE_INT, String
098: .valueOf(message), t);
099: }
100:
101: /**
102: * Converts the input parameter to String and then delegates to the wrapped
103: * <code>org.slf4j.Logger</code> instance.
104: *
105: * @param message the message to log. Converted to {@link String}
106: */
107: public void debug(Object message) {
108: logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String
109: .valueOf(message), null);
110: }
111:
112: /**
113: * Converts the first input parameter to String and then delegates to
114: * the wrapped <code>org.slf4j.Logger</code> instance.
115: *
116: * @param message the message to log. Converted to {@link String}
117: * @param t the exception to log
118: */
119: public void debug(Object message, Throwable t) {
120: logger.log(null, FQCN, LocationAwareLogger.DEBUG_INT, String
121: .valueOf(message), t);
122: }
123:
124: /**
125: * Converts the input parameter to String and then delegates to the wrapped
126: * <code>org.slf4j.Logger</code> instance.
127: *
128: * @param message the message to log. Converted to {@link String}
129: */
130: public void info(Object message) {
131: logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String
132: .valueOf(message), null);
133: }
134:
135: /**
136: * Converts the first input parameter to String and then delegates to
137: * the wrapped <code>org.slf4j.Logger</code> instance.
138: *
139: * @param message the message to log. Converted to {@link String}
140: * @param t the exception to log
141: */
142: public void info(Object message, Throwable t) {
143: logger.log(null, FQCN, LocationAwareLogger.INFO_INT, String
144: .valueOf(message), t);
145: }
146:
147: /**
148: * Converts the input parameter to String and then delegates to the wrapped
149: * <code>org.slf4j.Logger</code> instance.
150: *
151: * @param message the message to log. Converted to {@link String}
152: */
153: public void warn(Object message) {
154: logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String
155: .valueOf(message), null);
156: }
157:
158: /**
159: * Converts the first input parameter to String and then delegates to
160: * the wrapped <code>org.slf4j.Logger</code> instance.
161: *
162: * @param message the message to log. Converted to {@link String}
163: * @param t the exception to log
164: */
165: public void warn(Object message, Throwable t) {
166: logger.log(null, FQCN, LocationAwareLogger.WARN_INT, String
167: .valueOf(message), t);
168: }
169:
170: /**
171: * Converts the input parameter to String and then delegates to the wrapped
172: * <code>org.slf4j.Logger</code> instance.
173: *
174: * @param message the message to log. Converted to {@link String}
175: */
176: public void error(Object message) {
177: logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String
178: .valueOf(message), null);
179: }
180:
181: /**
182: * Converts the first input parameter to String and then delegates to
183: * the wrapped <code>org.slf4j.Logger</code> instance.
184: *
185: * @param message the message to log. Converted to {@link String}
186: * @param t the exception to log
187: */
188: public void error(Object message, Throwable t) {
189: logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String
190: .valueOf(message), t);
191: }
192:
193: /**
194: * Converts the input parameter to String and then delegates to
195: * the error method of the wrapped <code>org.slf4j.Logger</code> instance.
196: *
197: * @param message the message to log. Converted to {@link String}
198: */
199: public void fatal(Object message) {
200: logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String
201: .valueOf(message), null);
202: }
203:
204: /**
205: * Converts the first input parameter to String and then delegates to
206: * the error method of the wrapped <code>org.slf4j.Logger</code> instance.
207: *
208: * @param message the message to log. Converted to {@link String}
209: * @param t the exception to log
210: */
211: public void fatal(Object message, Throwable t) {
212: logger.log(null, FQCN, LocationAwareLogger.ERROR_INT, String
213: .valueOf(message), t);
214: }
215:
216: }
|