001: package net.sourceforge.squirrel_sql.fw.util.log;
002:
003: /*
004: * Copyright (C) 2001-2002 Colin Bell
005: * colbell@users.sourceforge.net
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this library; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: */
021: import org.apache.log4j.Level;
022: import org.apache.log4j.Logger;
023:
024: /**
025: * This is a logger that logs using the Apache log4j package.
026: *
027: * @author <A HREF="mailto:colbell@users.sourceforge.net">Colin Bell</A>
028: */
029: public class Log4jLogger implements ILogger {
030: /** Log4j logger to log to. */
031: private Logger _log;
032: private ILoggerListener _listener;
033: private Class<?> _clazz;
034:
035: /**
036: * Ctor specifying the object requesting the logger. A
037: * Log4J <TT>Logger</TT> is created using as a name the
038: * fully qualified class of <TT>requester</TT>.
039: *
040: * @param clazz The class requesting a logger.
041: *
042: * @throws IllegalArgumentException
043: * Thrown if <TT>clazz</TT> is <TT>null</TT>.
044: */
045: Log4jLogger(Class<?> clazz, ILoggerListener listener) {
046: if (clazz == null) {
047: throw new IllegalArgumentException(
048: "Empty requesterClass passed");
049: }
050:
051: if (listener == null) {
052: throw new IllegalArgumentException("Empty listener passed");
053: }
054:
055: _listener = listener;
056: _clazz = clazz;
057: _log = Logger.getLogger(clazz);
058: }
059:
060: /**
061: * @see ILogger#debug(Object)
062: */
063: public void debug(Object message) {
064: _log.debug(message);
065: }
066:
067: /**
068: * @see ILogger#debug(Object, Throwable)
069: */
070: public void debug(Object message, Throwable th) {
071: _log.debug(message, th);
072: }
073:
074: /**
075: * @see ILogger#info(Object)
076: */
077: public void info(Object message) {
078: _log.info(message);
079: _listener.info(_clazz, message);
080: }
081:
082: /**
083: * @see ILogger#info(Object, Throwable)
084: */
085: public void info(Object message, Throwable th) {
086: _log.info(message, th);
087: _listener.info(_clazz, message, th);
088: }
089:
090: /**
091: * @see ILogger#warn(Object)
092: */
093: public void warn(Object message) {
094: _log.warn(message);
095: _listener.warn(_clazz, message);
096: }
097:
098: /**
099: * @see ILogger#warn(Object, Throwable)
100: */
101: public void warn(Object message, Throwable th) {
102: _log.warn(message, th);
103: _listener.warn(_clazz, message, th);
104: }
105:
106: /**
107: * @see ILogger#error(Object)
108: */
109: public void error(Object message) {
110: _log.error(message);
111: _listener.error(_clazz, message);
112: }
113:
114: /**
115: * @see ILogger#error(Object, Throwable)
116: */
117: public void error(Object message, Throwable th) {
118: _log.error(message, th);
119: _listener.error(_clazz, message, th);
120: }
121:
122: /**
123: * @see ILogger#isDebugEnabled()
124: */
125: public boolean isDebugEnabled() {
126: return _log.isDebugEnabled();
127: }
128:
129: /**
130: * @see ILogger#isInfoEnabled()
131: */
132: public boolean isInfoEnabled() {
133: return _log.isInfoEnabled();
134: }
135:
136: /**
137: * Sets the log level of the logger. For instance:
138: *
139: * Level.ALL
140: * Level.DEBUG
141: * Level.ERROR
142: * Level.FATAL
143: * Level.INFO
144: * Level.OFF
145: * Level.WARN
146: *
147: * @param l the level to set the logger to.
148: */
149: public void setLevel(Level l) {
150: _log.setLevel(l);
151: }
152: }
|