MCPcopy
hub / github.com/qos-ch/slf4j / LoggerWrapper

Class LoggerWrapper

slf4j-ext/src/main/java/org/slf4j/ext/LoggerWrapper.java:40–813  ·  view source on GitHub ↗

A helper class wrapping an org.slf4j.Logger instance preserving location information if the wrapped instance supports it. @author Ralph Goers @author Ceki Gülcü

Source from the content-addressed store, hash-verified

38 * @author Ceki Gülcü
39 */
40public class LoggerWrapper implements Logger {
41
42 // To ensure consistency between two instances sharing the same name
43 // (homonyms) a LoggerWrapper should not contain any state beyond
44 // the Logger instance it wraps.
45 // Note that 'instanceofLAL' directly depends on Logger.
46 // fqcn depend on the caller, but its value would not be different
47 // between successive invocations of a factory class
48
49 protected final Logger logger;
50 final String fqcn;
51 // is this logger instance a LocationAwareLogger
52 protected final boolean instanceofLAL;
53
54 public LoggerWrapper(Logger logger, String fqcn) {
55 this.logger = logger;
56 this.fqcn = fqcn;
57 if (logger instanceof LocationAwareLogger) {
58 instanceofLAL = true;
59 } else {
60 instanceofLAL = false;
61 }
62 }
63
64 /**
65 * Delegate to the appropriate method of the underlying logger.
66 */
67 public boolean isTraceEnabled() {
68 return logger.isTraceEnabled();
69 }
70
71 /**
72 * Delegate to the appropriate method of the underlying logger.
73 */
74 public boolean isTraceEnabled(Marker marker) {
75 return logger.isTraceEnabled(marker);
76 }
77
78 /**
79 * Delegate to the appropriate method of the underlying logger.
80 */
81 public void trace(String msg) {
82 if (!logger.isTraceEnabled())
83 return;
84
85 if (instanceofLAL) {
86 ((LocationAwareLogger) logger).log(null, fqcn, LocationAwareLogger.TRACE_INT, msg, null, null);
87 } else {
88 logger.trace(msg);
89 }
90 }
91
92 /**
93 * Delegate to the appropriate method of the underlying logger.
94 */
95 public void trace(String format, Object arg) {
96 if (!logger.isTraceEnabled())
97 return;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected