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: /**
013: * Base class for simple Logger implementations (no patterns and so
014: * on).
015: *
016: * @author Michiel Meeuwissen
017: * @since MMBase-1.7
018: */
019:
020: abstract public class AbstractSimpleImpl implements Logger {
021:
022: /**
023: * @since MMBase-1.8
024: */
025: protected int level = Level.INFO_INT;
026:
027: public void setLevel(Level p) {
028: level = p.toInt();
029: }
030:
031: // override one of these two
032: /**
033: * How to write one string. Only to be called by {@link #log(String, Level)}. Default this does
034: * nothing, you must override this, or {@link #log(String, Level)}.
035: */
036: protected void log(String s) {
037: }
038:
039: /**
040: * Logs a message for a certain string. Default calls {@link #log(String)} where the string is
041: * prefixed with the level. Override this one if you want it differently.
042: */
043: protected void log(String s, Level level) {
044: log(level.toString() + " " + s);
045: }
046:
047: /**
048: * Override to implement different stringification of objects to log. (default "" + s)
049: * @since MMBase-1.8
050: */
051: protected void log(Object s, Level level) {
052: log("" + s, level);
053: }
054:
055: /**
056: * @since MMBase-1.8
057: */
058: protected void log(Object s, Throwable t) {
059: log("" + s + "\n" + Logging.stackTrace(t));
060: }
061:
062: /**
063: * @since MMBase-1.8
064: */
065: protected void log(Object s, Level level, Throwable t) {
066: log(s, t);
067: }
068:
069: public void trace(Object m) {
070: if (level <= Level.TRACE_INT) {
071: log(m, Level.TRACE);
072: }
073: }
074:
075: public void trace(Object m, Throwable t) {
076: if (level <= Level.TRACE_INT) {
077: log(m, Level.TRACE, t);
078: }
079: }
080:
081: public void debug(Object m) {
082: if (level <= Level.DEBUG_INT) {
083: log(m, Level.DEBUG);
084: }
085: }
086:
087: public void debug(Object m, Throwable t) {
088: if (level <= Level.DEBUG_INT) {
089: log(m, Level.DEBUG, t);
090: }
091: }
092:
093: public void service(Object m) {
094: if (level <= Level.SERVICE_INT) {
095: log(m, Level.SERVICE);
096: }
097: }
098:
099: public void service(Object m, Throwable t) {
100: if (level <= Level.SERVICE_INT) {
101: log(m, Level.SERVICE, t);
102: }
103: }
104:
105: public void info(Object m) {
106: if (level <= Level.INFO_INT) {
107: log(m, Level.INFO);
108: }
109: }
110:
111: public void info(Object m, Throwable t) {
112: if (level <= Level.INFO_INT) {
113: log(m, Level.INFO, t);
114: }
115: }
116:
117: public void warn(Object m) {
118: if (level <= Level.WARN_INT) {
119: log(m, Level.WARN);
120: }
121: }
122:
123: public void warn(Object m, Throwable t) {
124: if (level <= Level.WARN_INT) {
125: log(m, Level.WARN, t);
126: }
127: }
128:
129: public void error(Object m) {
130: if (level <= Level.ERROR_INT) {
131: log(m, Level.ERROR);
132: }
133: }
134:
135: public void error(Object m, Throwable t) {
136: if (level <= Level.ERROR_INT) {
137: log(m, Level.ERROR, t);
138: }
139: }
140:
141: public void fatal(Object m) {
142: if (level <= Level.FATAL_INT) {
143: log(m, Level.FATAL);
144: }
145: }
146:
147: public void fatal(Object m, Throwable t) {
148: if (level <= Level.FATAL_INT) {
149: log(m, Level.FATAL, t);
150: }
151: }
152:
153: public boolean isTraceEnabled() {
154: return level <= Level.TRACE_INT;
155: }
156:
157: public boolean isDebugEnabled() {
158: return level <= Level.DEBUG_INT;
159: }
160:
161: public boolean isServiceEnabled() {
162: return level <= Level.SERVICE_INT;
163: }
164:
165: }
|