rwaldhoff 01/08/15 14:23:23 Modified: logging/src/java/org/apache/commons/logging SimpleLog.java NoOpLog.java LogSource.java Log4JCategoryLog.java Log.java Log: adding setLevel/getLevel methods, as was done to the httpclient version last week Revision Changes Path 1.6 +10 -1 jakarta-commons-sandbox/logging/src/java/org/apache/commons/logging/SimpleLog.java Index: SimpleLog.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/logging/src/java/org/apache/commons/logging/SimpleLog.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- SimpleLog.java 2001/08/15 16:48:56 1.5 +++ SimpleLog.java 2001/08/15 21:23:23 1.6 @@ -17,7 +17,7 @@ /** * @author Rod Waldhoff - * @version $Id: SimpleLog.java,v 1.5 2001/08/15 16:48:56 craigmcc Exp $ + * @version $Id: SimpleLog.java,v 1.6 2001/08/15 21:23:23 rwaldhoff Exp $ */ public class SimpleLog implements Log { static protected final String _prefix = @@ -169,4 +169,13 @@ public final boolean isInfoEnabled() { return (_logLevel >= INFO); } + + public final void setLevel(int level) { + _logLevel = level; + } + + public final int getLevel() { + return _logLevel; + } + } 1.6 +3 -1 jakarta-commons-sandbox/logging/src/java/org/apache/commons/logging/NoOpLog.java Index: NoOpLog.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/logging/src/java/org/apache/commons/logging/NoOpLog.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- NoOpLog.java 2001/08/15 16:48:56 1.5 +++ NoOpLog.java 2001/08/15 21:23:23 1.6 @@ -12,7 +12,7 @@ * Default implementation of Log that throws away all messages. * * @author Rod Waldhoff - * @version $Id: NoOpLog.java,v 1.5 2001/08/15 16:48:56 craigmcc Exp $ + * @version $Id: NoOpLog.java,v 1.6 2001/08/15 21:23:23 rwaldhoff Exp $ */ public final class NoOpLog implements Log { public NoOpLog() { } @@ -29,4 +29,6 @@ public void fatal(Object message, Throwable t) { } public final boolean isDebugEnabled() { return false; } public final boolean isInfoEnabled() { return false; } + public final void setLevel(int level) { } + public final int getLevel() { return Log.OFF; } } 1.4 +23 -1 jakarta-commons-sandbox/logging/src/java/org/apache/commons/logging/LogSource.java Index: LogSource.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/logging/src/java/org/apache/commons/logging/LogSource.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- LogSource.java 2001/08/15 16:48:56 1.3 +++ LogSource.java 2001/08/15 21:23:23 1.4 @@ -10,12 +10,13 @@ import java.util.HashMap; import java.lang.reflect.Constructor; +import java.util.Iterator; /** * Factory for creating {@link Log} instances. * * @author Rod Waldhoff - * @version $Id: LogSource.java,v 1.3 2001/08/15 16:48:56 craigmcc Exp $ + * @version $Id: LogSource.java,v 1.4 2001/08/15 21:23:23 rwaldhoff Exp $ */ public class LogSource { static protected HashMap _logs = new HashMap(); @@ -96,4 +97,25 @@ } return log; } + + /** + * Sets the log level for all {@link Log}s known + * to me. + */ + static public void setLevel(int level) { + Iterator it = _logs.entrySet().iterator(); + while(it.hasNext()) { + Log log = (Log)(it.next()); + log.setLevel(level); + } + } + + /** + * Returns an iterator over the names of + * all logs known to me. + */ + static public Iterator getLogNames() { + return _logs.keySet().iterator(); + } + } 1.6 +29 -1 jakarta-commons-sandbox/logging/src/java/org/apache/commons/logging/Log4JCategoryLog.java Index: Log4JCategoryLog.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/logging/src/java/org/apache/commons/logging/Log4JCategoryLog.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Log4JCategoryLog.java 2001/08/15 16:48:56 1.5 +++ Log4JCategoryLog.java 2001/08/15 21:23:23 1.6 @@ -16,7 +16,7 @@ * <strong>Category</strong>. * * @author Rod Waldhoff - * @version $Id: Log4JCategoryLog.java,v 1.5 2001/08/15 16:48:56 craigmcc Exp $ + * @version $Id: Log4JCategoryLog.java,v 1.6 2001/08/15 21:23:23 rwaldhoff Exp $ */ public class Log4JCategoryLog implements Log { Category _category = null; @@ -75,4 +75,32 @@ public final boolean isEnabledFor(Priority p) { return _category.isEnabledFor(p); } + + public final void setLevel(int level) { + switch(level) { + case Log.DEBUG: + _category.setPriority(Priority.DEBUG); + break; + case Log.INFO: + _category.setPriority(Priority.INFO); + break; + case Log.WARN: + _category.setPriority(Priority.WARN); + break; + case Log.ERROR: + _category.setPriority(Priority.ERROR); + break; + case Log.FATAL: + _category.setPriority(Priority.FATAL); + break; + default: + _category.setPriority(Priority.toPriority(level)); + break; + } + } + + public final int getLevel() { + return _category.getPriority().toInt(); + } + } 1.6 +18 -1 jakarta-commons-sandbox/logging/src/java/org/apache/commons/logging/Log.java Index: Log.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/logging/src/java/org/apache/commons/logging/Log.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Log.java 2001/08/15 16:48:56 1.5 +++ Log.java 2001/08/15 21:23:23 1.6 @@ -15,7 +15,7 @@ * parameter representing the "name" of this Log. * * @author Rod Waldhoff - * @version $Id: Log.java,v 1.5 2001/08/15 16:48:56 craigmcc Exp $ + * @version $Id: Log.java,v 1.6 2001/08/15 21:23:23 rwaldhoff Exp $ */ public interface Log { public void debug(Object message); @@ -30,4 +30,21 @@ public void fatal(Object message, Throwable t); public boolean isDebugEnabled(); public boolean isInfoEnabled(); + public void setLevel(int level); + public int getLevel(); + + /** All logging level. */ + public static final int ALL = Integer.MIN_VALUE; + /** "Debug" level logging. */ + public static final int DEBUG = 10000; + /** "Info" level logging. */ + public static final int INFO = 20000; + /** "Warn" level logging. */ + public static final int WARN = 30000; + /** "Error" level logging. */ + public static final int ERROR = 40000; + /** "Fatal" level logging. */ + public static final int FATAL = 50000; + /** No logging level. */ + public static final int OFF = Integer.MAX_VALUE; }