001: /*
002: This software is OSI Certified Open Source Software.
003: OSI Certified is a certification mark of the Open Source Initiative.
004:
005: The license (Mozilla version 1.0) can be read at the MMBase site.
006: See http://www.MMBase.org/license
007:
008: */
009:
010: package org.mmbase.util.logging;
011:
012: import java.util.*;
013:
014: /**
015: * Wraps a logger instance. This can be used for static logger instances which might be instatatied
016: * before logging itself is configured. After configurating logging, all static 'wrappers' can then
017: * be called to wrap another logger instance.
018: *
019: * @author Michiel Meeuwissen
020: * @since MMBase-1.7
021: * @version $Id: LoggerWrapper.java,v 1.9 2008/02/11 16:11:02 michiel Exp $
022: **/
023:
024: public class LoggerWrapper implements Logger {
025:
026: private static final Set<LoggerWrapper> wrappers = new HashSet<LoggerWrapper>();
027:
028: // package
029: static Set<LoggerWrapper> getWrappers() {
030: return Collections.unmodifiableSet(wrappers);
031: }
032:
033: private Logger log;
034: private final String name;
035:
036: // package
037: LoggerWrapper(Logger log, String name) {
038: this .name = name;
039: setLogger(log);
040: wrappers.add(this );
041: }
042:
043: // package
044: String getName() {
045: return name;
046: }
047:
048: // package
049: Logger setLogger(Logger log) {
050: if (log == null) {
051: if (this .log == null) {
052: log = SimpleImpl.getLoggerInstance(name);
053: } else {
054: log = this .log;
055: }
056: System.err
057: .println("Tried to instantiate logger wrapper with null!");
058: log.error("Tried to instantiate logger wrapper with null!",
059: new Exception());
060: }
061: Logger org = this .log;
062: this .log = log;
063: return org;
064: }
065:
066: final public void trace(Object m) {
067: if (log != null)
068: log.trace(m);
069: }
070:
071: final public void trace(Object m, Throwable t) {
072: if (log != null)
073: log.trace(m, t);
074: }
075:
076: final public void debug(Object m) {
077: if (log != null)
078: log.debug(m);
079: }
080:
081: final public void debug(Object m, Throwable t) {
082: if (log != null)
083: log.debug(m, t);
084: }
085:
086: final public void service(Object m) {
087: log.service(m);
088: }
089:
090: final public void service(Object m, Throwable t) {
091: log.service(m, t);
092: }
093:
094: final public void info(Object m) {
095: log.info(m);
096: }
097:
098: final public void info(Object m, Throwable t) {
099: log.info(m, t);
100: }
101:
102: final public void warn(Object m) {
103: log.warn(m);
104: }
105:
106: final public void warn(Object m, Throwable t) {
107: log.warn(m, t);
108: }
109:
110: final public void error(Object m) {
111: log.error(m);
112: }
113:
114: final public void error(Object m, Throwable t) {
115: log.error(m, t);
116: }
117:
118: final public void fatal(Object m) {
119: log.fatal(m);
120: }
121:
122: final public void fatal(Object m, Throwable t) {
123: log.fatal(m, t);
124: }
125:
126: final public boolean isTraceEnabled() {
127: return log.isTraceEnabled();
128: }
129:
130: final public boolean isDebugEnabled() {
131: return log.isDebugEnabled();
132: }
133:
134: final public boolean isServiceEnabled() {
135: return log.isServiceEnabled();
136: }
137:
138: final public void setLevel(Level p) {
139: log.setLevel(p);
140: }
141:
142: }
|