1
0

Update to add a trace() level to the Log interface.

Currently uses debug() in Log4J and LogKit
PR:
Obtained from:
Submitted by:
Reviewed by:


git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/logging/trunk@138850 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Scott Sanders
2002-01-31 00:14:31 +00:00
parent 8d3cf2e4ac
commit 84958f29b7
6 changed files with 337 additions and 175 deletions

View File

@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Attic/Jdk14Logger.java,v 1.4 2002/01/30 03:56:26 craigmcc Exp $
* $Revision: 1.4 $
* $Date: 2002/01/30 03:56:26 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Attic/Jdk14Logger.java,v 1.5 2002/01/31 00:14:31 sanders Exp $
* $Revision: 1.5 $
* $Date: 2002/01/31 00:14:31 $
*
* ====================================================================
*
@@ -72,9 +72,10 @@ import java.util.logging.Logger;
* interfaces that wraps the standard JDK logging mechanisms that were
* introduced in the Merlin release (JDK 1.4).</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
* @version $Revision: 1.4 $ $Date: 2002/01/30 03:56:26 $
* @version $Revision: 1.5 $ $Date: 2002/01/31 00:14:31 $
*/
public final class Jdk14Logger implements Log {
@@ -239,6 +240,16 @@ public final class Jdk14Logger implements Log {
}
/**
* Is tace logging currently enabled?
*/
public boolean isTraceEnabled() {
return (logger.isLoggable(Level.FINEST));
}
/**
* Is warning logging currently enabled?
*/
@@ -249,6 +260,26 @@ public final class Jdk14Logger implements Log {
}
/**
* Log a message with trace log level.
*/
public void trace(Object message) {
logger.log(Level.FINEST, message.toString());
}
/**
* Log a message and exception with trace log level.
*/
public void trace(Object message, Throwable exception) {
logger.log(Level.FINEST, message.toString(), exception);
}
/**
* Log a message with warn log level.
*/

View File

@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Log.java,v 1.11 2002/01/23 20:14:30 rdonkin Exp $
* $Revision: 1.11 $
* $Date: 2002/01/23 20:14:30 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Log.java,v 1.12 2002/01/31 00:14:31 sanders Exp $
* $Revision: 1.12 $
* $Date: 2002/01/31 00:14:31 $
*
* ====================================================================
*
@@ -68,9 +68,10 @@ package org.apache.commons.logging;
* this interface must have a constructor that takes a single String
* parameter representing the "name" of this Log.</p>
*
* <p> The five logging levels used by <code>Log</code> are (in order):
* <p> The six logging levels used by <code>Log</code> are (in order):
* <ol>
* <li>debug (the least serious)</li>
* <li>trace (the least serious)</li>
* <li>debug</li>
* <li>info</li>
* <li>warn</li>
* <li>error</li>
@@ -99,8 +100,9 @@ package org.apache.commons.logging;
* external to the Logging APIs, through whatever mechanism is supported by
* that system.</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author Rod Waldhoff
* @version $Id: Log.java,v 1.11 2002/01/23 20:14:30 rdonkin Exp $
* @version $Id: Log.java,v 1.12 2002/01/31 00:14:31 sanders Exp $
*/
public interface Log {
@@ -148,6 +150,16 @@ public interface Log {
public boolean isInfoEnabled();
/**
* <p> Is trace logging currently enabled? </p>
*
* <p> Call this method to prevent having to perform expensive operations
* (for example, <code>String</code> concatination)
* when the log level is more than trace. </p>
*/
public boolean isTraceEnabled();
/**
* <p> Is warning logging currently enabled? </p>
*
@@ -161,6 +173,23 @@ public interface Log {
// -------------------------------------------------------- Logging Methods
/**
* <p> Log a message with trace log level </p>
*
* @param message log this message
*/
public void trace(Object message);
/**
* <p> Log an error with trace log level </p>
*
* @param message log this message
* @param t log this cause
*/
public void trace(Object message, Throwable t);
/**
* <p> Log a message with debug log level </p>
*

View File

@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Attic/Log4JCategoryLog.java,v 1.9 2002/01/24 18:29:36 rdonkin Exp $
* $Revision: 1.9 $
* $Date: 2002/01/24 18:29:36 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Attic/Log4JCategoryLog.java,v 1.10 2002/01/31 00:14:31 sanders Exp $
* $Revision: 1.10 $
* $Date: 2002/01/31 00:14:31 $
*
* ====================================================================
*
@@ -71,10 +71,10 @@ import org.apache.log4j.Priority;
* Category instances should be done in the usual manner, as outlined in
* the Log4J documentation.</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author Rod Waldhoff
* @author Robert Burrell Donkin
*
* @version $Id: Log4JCategoryLog.java,v 1.9 2002/01/24 18:29:36 rdonkin Exp $
* @version $Id: Log4JCategoryLog.java,v 1.10 2002/01/31 00:14:31 sanders Exp $
*/
public final class Log4JCategoryLog implements Log {
@@ -100,6 +100,24 @@ public final class Log4JCategoryLog implements Log {
// ---------------------------------------------------------- Implmentation
/**
* Log a message to the Log4j Category with <code>TRACE</code> priority.
* Currently logs to <code>DEBUG</code> level in Log4J.
*/
public void trace(Object message) {
category.debug(message);
}
/**
* Log an error to the Log4j Category with <code>TRACE</code> priority.
* Currently logs to <code>DEBUG</code> level in Log4J.
*/
public void trace(Object message, Throwable t) {
category.debug(message,t);
}
/**
* Log a message to the Log4j Category with <code>DEBUG</code> priority.
*/
@@ -212,6 +230,14 @@ public final class Log4JCategoryLog implements Log {
}
/**
* Check whether the Log4j Category used is enabled for <code>TRACE</code> priority.
* For Log4J, this returns the value of <code>isDebugEnabled()</code>
*/
public boolean isTraceEnabled() {
return category.isDebugEnabled();
}
/**
* Check whether the Log4j Category used is enabled for <code>WARN</code> priority.
*/

View File

@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Attic/LogKitLogger.java,v 1.3 2002/01/24 19:02:35 rdonkin Exp $
* $Revision: 1.3 $
* $Date: 2002/01/24 19:02:35 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Attic/LogKitLogger.java,v 1.4 2002/01/31 00:14:31 sanders Exp $
* $Revision: 1.4 $
* $Date: 2002/01/31 00:14:31 $
*
* ====================================================================
*
@@ -74,9 +74,9 @@ import org.apache.log.Hierarchy;
* Therefore, this implementation converts object messages into strings
* by called their <code>toString()</code> method before logging them.</p>
*
* @author Robert Burrell Donkin
*
* @version $Id: LogKitLogger.java,v 1.3 2002/01/24 19:02:35 rdonkin Exp $
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author Robert Burrell Donkin *
* @version $Id: LogKitLogger.java,v 1.4 2002/01/31 00:14:31 sanders Exp $
*/
public final class LogKitLogger implements Log {
@@ -106,6 +106,22 @@ public final class LogKitLogger implements Log {
// ----------------------------------------------------- Log Implementation
/**
* Log message to <code>LogKit</code> logger with <code>DEBUG</code> priority.
*/
public void trace(Object message) {
debug(message);
}
/**
* Log error to <code>LogKit</code> logger with <code>DEBUG</code> priority.
*/
public void trace(Object message, Throwable t) {
debug(message, t);
}
/**
* Log message to <code>LogKit</code> logger with <code>DEBUG</code> priority.
*/
@@ -238,6 +254,14 @@ public final class LogKitLogger implements Log {
}
/**
* Check whether the <code>LogKit</code> logger will log messages of priority <code>DEBUG</code>.
*/
public boolean isTraceEnabled() {
return logger.isDebugEnabled();
}
/**
* Check whether the <code>LogKit</code> logger will log messages of priority <code>WARN</code>.
*/

View File

@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Attic/NoOpLog.java,v 1.8 2002/01/17 01:47:49 craigmcc Exp $
* $Revision: 1.8 $
* $Date: 2002/01/17 01:47:49 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Attic/NoOpLog.java,v 1.9 2002/01/31 00:14:31 sanders Exp $
* $Revision: 1.9 $
* $Date: 2002/01/31 00:14:31 $
*
* ====================================================================
*
@@ -66,8 +66,9 @@ package org.apache.commons.logging;
* <p>Default implementation of Log that throws away all messages. No
* configurable system properties are supported.</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author Rod Waldhoff
* @version $Id: NoOpLog.java,v 1.8 2002/01/17 01:47:49 craigmcc Exp $
* @version $Id: NoOpLog.java,v 1.9 2002/01/31 00:14:31 sanders Exp $
*/
public final class NoOpLog implements Log {
@@ -76,6 +77,10 @@ public final class NoOpLog implements Log {
/** Base constructor */
public NoOpLog(String name) { }
/** Do nothing */
public void trace(Object message) { }
/** Do nothing */
public void trace(Object message, Throwable t) { }
/** Do nothing */
public void debug(Object message) { }
/** Do nothing */
public void debug(Object message, Throwable t) { }
@@ -124,6 +129,13 @@ public final class NoOpLog implements Log {
*/
public final boolean isInfoEnabled() { return false; }
/**
* Trace is never enabled.
*
* @return false
*/
public final boolean isTraceEnabled() { return false; }
/**
* Warning is never enabled.
*
@@ -131,5 +143,4 @@ public final class NoOpLog implements Log {
*/
public final boolean isWarnEnabled() { return false; }
}

View File

@@ -1,7 +1,7 @@
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Attic/SimpleLog.java,v 1.11 2002/01/25 18:41:48 sanders Exp $
* $Revision: 1.11 $
* $Date: 2002/01/25 18:41:48 $
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//logging/src/java/org/apache/commons/logging/Attic/SimpleLog.java,v 1.12 2002/01/31 00:14:31 sanders Exp $
* $Revision: 1.12 $
* $Date: 2002/01/31 00:14:31 $
*
* ====================================================================
*
@@ -76,11 +76,11 @@ import java.util.Date;
* <ul>
* <li><code>org.apache.commons.logging.simplelog.defaultlog</code> -
* Default logging detail level for all instances of SimpleLog.
* Must be one of ("debug", "info", "warn", "error", or "fatal").
* Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
* If not specified, defaults to "error". </li>
* <li><code>org.apache.commons.logging.simplelog.log.xxxxx</code> -
* Logging detail level for a SimpleLog instance named "xxxxx".
* Must be one of ("debug", "info", "warn", "error", or "fatal").
* Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
* If not specified, the default logging detail level is used.</li>
* <li><code>org.apache.commons.logging.simplelog.showlogname</code> -
* Set to <code>true</code> if you want the Log instance name to be
@@ -95,10 +95,11 @@ import java.util.Date;
* <code>"simplelog.properties"</code>, and includes any matching definitions
* from this resource (if it exists).</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author Rod Waldhoff
* @author Robert Burrell Donkin
*
* @version $Id: SimpleLog.java,v 1.11 2002/01/25 18:41:48 sanders Exp $
* @version $Id: SimpleLog.java,v 1.12 2002/01/31 00:14:31 sanders Exp $
*/
public class SimpleLog implements Log {
@@ -121,19 +122,21 @@ public class SimpleLog implements Log {
// ---------------------------------------------------- Log Level Constants
/** "Trace" level logging. */
public static final int LOG_LEVEL_TRACE = 1;
/** "Debug" level logging. */
public static final int LOG_LEVEL_DEBUG = 1;
public static final int LOG_LEVEL_DEBUG = 2;
/** "Info" level logging. */
public static final int LOG_LEVEL_INFO = 2;
public static final int LOG_LEVEL_INFO = 3;
/** "Warn" level logging. */
public static final int LOG_LEVEL_WARN = 3;
public static final int LOG_LEVEL_WARN = 4;
/** "Error" level logging. */
public static final int LOG_LEVEL_ERROR = 4;
public static final int LOG_LEVEL_ERROR = 5;
/** "Fatal" level logging. */
public static final int LOG_LEVEL_FATAL = 5;
public static final int LOG_LEVEL_FATAL = 6;
/** Enable all logging levels */
public static final int LOG_LEVEL_ALL = (LOG_LEVEL_DEBUG - 1);
public static final int LOG_LEVEL_ALL = (LOG_LEVEL_TRACE - 1);
/** Enable no logging levels */
public static final int LOG_LEVEL_OFF = (LOG_LEVEL_FATAL + 1);
@@ -217,6 +220,8 @@ public class SimpleLog implements Log {
if("all".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_ALL);
} else if("trace".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_TRACE);
} else if("debug".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_DEBUG);
} else if("info".equalsIgnoreCase(lvl)) {
@@ -276,6 +281,7 @@ public class SimpleLog implements Log {
// append a readable representation of the log leve
switch(type) {
case SimpleLog.LOG_LEVEL_TRACE: buf.append("[TRACE] "); break;
case SimpleLog.LOG_LEVEL_DEBUG: buf.append("[DEBUG] "); break;
case SimpleLog.LOG_LEVEL_INFO: buf.append("[INFO] "); break;
case SimpleLog.LOG_LEVEL_WARN: buf.append("[WARN] "); break;
@@ -341,6 +347,28 @@ public class SimpleLog implements Log {
}
/**
* <p> Log a message with debug log level.</p>
*/
public final void trace(Object message) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
log(SimpleLog.LOG_LEVEL_TRACE, message, null);
}
}
/**
* <p> Log an error with debug log level.</p>
*/
public final void trace(Object message, Throwable t) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
log(SimpleLog.LOG_LEVEL_TRACE, message, t);
}
}
/**
* <p> Log a message with info log level.</p>
*/
@@ -481,6 +509,19 @@ public class SimpleLog implements Log {
}
/**
* <p> Are trace messages currently enabled? </p>
*
* <p> This allows expensive operations such as <code>String</code>
* concatenation to be avoided when the message will be ignored by the
* logger. </p>
*/
public final boolean isTraceEnabled() {
return isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE);
}
/**
* <p> Are warn messages currently enabled? </p>
*