- Migrating to modified printing methods as discussed on the slf4j-dev

mailing lists.

 debug(String msg);
 debug(String msg, Throwable t);
 debug(String format, Object arg);
 debug(String format, Object arg, Object arg2);
 debug(String format, Object[] args);

- Javadoc changes.

- This is still work in progress.
This commit is contained in:
Ceki Gulcu 2005-06-27 19:44:42 +00:00
parent f232562c5f
commit bd66655e8c
6 changed files with 285 additions and 199 deletions

View File

@ -25,8 +25,6 @@
<echo>
These are some of the targets supported by this ANT build scpript:
build.core - compile core SLF4J files.
slf4j-nop.jar - build the jar file of the same name.
slf4j-simple.jar - build the jar file of the same name.
slf4j-jdk14.jar - build the jar file of the same name.
@ -47,25 +45,6 @@
<delete dir="${javac.dest}/org/slf4j" />
</target>
<!-- ================================================================== -->
<!-- Copy SLF4J files into log4j source tree. This step is necessary for -->
<!-- building log4j. However, it needs to be done whenever code in SLF4J -->
<!-- changes -->
<!-- ================================================================== -->
<target name="copy-into-log4j">
<!-- delete any stale copy of LoggerFactory.java -->
<delete><fileset dir="src/java/org/apache/slf4j" includes="LoggerFactory.java"/></delete>
<!-- copy a filtered version of slf4j to tmp/src -->
<copy todir="src/java">
<fileset dir="src/filtered-java">
<include name="**/*.java"/>
<exclude name="**/impl/JDK14*.java"/>
</fileset>
<filterset><filter token="IMPL" value="Log4j"/></filterset>
</copy>
</target>
<target name="julCheck">
<available classname="java.util.logging.Logger" property="julPresent">

View File

@ -34,8 +34,8 @@ package org.slf4j;
/**
*
* The main user inteface to logging. It is expected that logging
* takes places through concerete implemetations of the Logger
* The main user interface to logging. It is expected that logging
* takes places through concrete implementations of the Logger
* interface.
*
* @author Ceki G&uuml;lc&uuml;
@ -50,55 +50,191 @@ public interface Logger {
public boolean isDebugEnabled();
/**
* Log a message object with the DEBUG level.
* @param msg - the message object to be logged
* Log a message at the DEBUG level.
*
* @param msg the message string to be logged
*/
public void debug(Object msg);
public void debug(String msg);
/**
* Log a parameterized message object at the DEBUG level.
* Log a message at the DEBUG level according to the specified format
* and argument.
*
* <p>This form is useful in avoiding the superflous object creation
* problem when invoking this method while it is disabled.
* </p>
* @param parameterizedMsg - the parameterized message object
* @param param1 - the parameter
* <p>This form avoids superfluous object creation when the logger
* is disabled for the DEBUG level. </p>
*
* @param format the format string
* @param arg the argument
*/
public void debug(Object parameterizedMsg, Object param1);
public void debug(String format, Object arg);
/**
* Log a parameterized message object at the DEBUG level.
* Log a message at the DEBUG level according to the specified format
* and arguments.
*
* <p>This form is useful in avoiding the superflous object creation
* problem when invoking this method while it is disabled.
* </p>
* @param parameterizedMsg - the parameterized message object
* @param param1 - the first parameter
* @param param2 - the second parameter
* <p>This form avoids superfluous object creation when the logger
* is disabled for the DEBUG level. </p>
*
* @param format the format string
* @param arg1 the first argument
* @param arg2 the second argument
*/
public void debug(String parameterizedMsg, Object param1, Object param2);
public void debug(Object msg, Throwable t);
public void debug(String format, Object arg1, Object arg2);
/**
* Log an exception (throwable) at the DEBUG level with an
* accompanying message.
*
* @param msg the message accompanying the exception
* @param t the exception (throwable) to log
*/
public void debug(String msg, Throwable t);
/**
* Is the logger instance enabled for the INFO level?
* @return True if this Logger is enabled for the INFO level,
* false otherwise.
*/
public boolean isInfoEnabled();
public void info(Object msg);
public void info(Object parameterizedMsg, Object param1);
public void info(String parameterizedMsg, Object param1, Object param2);
public void info(Object msg, Throwable t);
/**
* Log a message at the INFO level.
*
* @param msg the message string to be logged
*/
public void info(String msg);
/**
* Log a message at the INFO level according to the specified format
* and argument.
*
* <p>This form avoids superfluous object creation when the logger
* is disabled for the INFO level. </p>
*
* @param format the format string
* @param arg the argument
*/
public void info(String format, Object arg);
/**
* Log a message at the INFO level according to the specified format
* and arguments.
*
* <p>This form avoids superfluous object creation when the logger
* is disabled for the INFO level. </p>
*
* @param format the format string
* @param arg1 the first argument
* @param arg2 the second argument
*/
public void info(String format, Object arg1, Object arg2);
/**
* Log an exception (throwable) at the INFO level with an
* accompanying message.
*
* @param msg the message accompanying the exception
* @param t the exception (throwable) to log
*/
public void info(String msg, Throwable t);
/**
* Is the logger instance enabled for the WARN level?
* @return True if this Logger is enabled for the WARN level,
* false otherwise.
*/
public boolean isWarnEnabled();
public void warn(Object msg);
public void warn(Object parameterizedMsg, Object param1);
public void warn(String parameterizedMsg, Object param1, Object param2);
public void warn(Object msg, Throwable t);
/**
* Log a message at the WARN level.
*
* @param msg the message string to be logged
*/
public void warn(String msg);
/**
* Log a message at the WARN level according to the specified format
* and argument.
*
* <p>This form avoids superfluous object creation when the logger
* is disabled for the WARN level. </p>
*
* @param format the format string
* @param arg the argument
*/
public void warn(String format, Object arg);
/**
* Log a message at the WARN level according to the specified format
* and arguments.
*
* <p>This form avoids superfluous object creation when the logger
* is disabled for the WARN level. </p>
*
* @param format the format string
* @param arg1 the first argument
* @param arg2 the second argument
*/
public void warn(String format, Object arg1, Object arg2);
/**
* Log an exception (throwable) at the WARN level with an
* accompanying message.
*
* @param msg the message accompanying the exception
* @param t the exception (throwable) to log
*/
public void warn(String msg, Throwable t);
/**
* Is the logger instance enabled for the ERROR level?
* @return True if this Logger is enabled for the ERROR level,
* false otherwise.
*/
public boolean isErrorEnabled();
public void error(Object msg);
public void error(Object parameterizedMsg, Object param1);
public void error(String parameterizedMsg, Object param1, Object param2);
public void error(Object msg, Throwable t);
/**
* Log a message at the ERROR level.
*
* @param msg the message string to be logged
*/
public void error(String msg);
/**
* Log a message at the ERROR level according to the specified format
* and argument.
*
* <p>This form avoids superfluous object creation when the logger
* is disabled for the ERROR level. </p>
*
* @param format the format string
* @param arg the argument
*/
public void error(String format, Object arg);
/**
* Log a message at the ERROR level according to the specified format
* and arguments.
*
* <p>This form avoids superfluous object creation when the logger
* is disabled for the ERROR level. </p>
*
* @param format the format string
* @param arg1 the first argument
* @param arg2 the second argument
*/
public void error(String format, Object arg1, Object arg2);
/**
* Log an exception (throwable) at the ERROR level with an
* accompanying message.
*
* @param msg the message accompanying the exception
* @param t the exception (throwable) to log
*/
public void error(String msg, Throwable t);
}

View File

@ -67,7 +67,7 @@ public class JDK14Logger implements Logger {
* Log a message object with the DEBUG level.
* @param msg - the message object to be logged
*/
public void debug(Object msg) {
public void debug(String msg) {
logger.fine(String.valueOf(msg));
}
@ -80,7 +80,7 @@ public class JDK14Logger implements Logger {
* @param parameterizedMsg - the parameterized message object
* @param param1 - the parameter
*/
public void debug(Object parameterizedMsg, Object param1) {
public void debug(String parameterizedMsg, Object param1) {
if (logger.isLoggable(Level.FINE)) {
if (parameterizedMsg instanceof String) {
String msgStr = (String) parameterizedMsg;
@ -118,7 +118,7 @@ public class JDK14Logger implements Logger {
}
}
public void debug(Object msg, Throwable t) {
public void debug(String msg, Throwable t) {
logger.log(Level.FINE, msg.toString(), t);
}
@ -126,11 +126,11 @@ public class JDK14Logger implements Logger {
return logger.isLoggable(Level.INFO);
}
public void info(Object msg) {
public void info(String msg) {
logger.info(msg.toString());
}
public void info(Object parameterizedMsg, Object param1) {
public void info(String parameterizedMsg, Object param1) {
if (logger.isLoggable(Level.INFO)) {
if (parameterizedMsg instanceof String) {
String msgStr = (String) parameterizedMsg;
@ -158,7 +158,7 @@ public class JDK14Logger implements Logger {
}
}
public void info(Object msg, Throwable t) {
public void info(String msg, Throwable t) {
logger.log(Level.INFO, msg.toString(), t);
}
@ -166,11 +166,11 @@ public class JDK14Logger implements Logger {
return logger.isLoggable(Level.WARNING);
}
public void warn(Object msg) {
public void warn(String msg) {
logger.warning(msg.toString());
}
public void warn(Object parameterizedMsg, Object param1) {
public void warn(String parameterizedMsg, Object param1) {
if (logger.isLoggable(Level.WARNING)) {
if (parameterizedMsg instanceof String) {
String msgStr = (String) parameterizedMsg;
@ -198,7 +198,7 @@ public class JDK14Logger implements Logger {
}
}
public void warn(Object msg, Throwable t) {
public void warn(String msg, Throwable t) {
logger.log(Level.WARNING, msg.toString(), t);
}
@ -206,11 +206,11 @@ public class JDK14Logger implements Logger {
return logger.isLoggable(Level.SEVERE);
}
public void error(Object msg) {
public void error(String msg) {
logger.severe(msg.toString());
}
public void error(Object parameterizedMsg, Object param1) {
public void error(String parameterizedMsg, Object param1) {
if (logger.isLoggable(Level.WARNING)) {
if (parameterizedMsg instanceof String) {
String msgStr = (String) parameterizedMsg;
@ -237,7 +237,7 @@ public class JDK14Logger implements Logger {
}
}
}
public void error(Object msg, Throwable t) {
public void error(String msg, Throwable t) {
logger.log(Level.SEVERE, msg.toString(), t);
}
}

View File

@ -37,7 +37,7 @@ import org.slf4j.Logger;
/**
* A no operation (NOP) implementation of {@link Logger}.
* A direct NOP (no operation) implementation of {@link Logger}.
*
* @author Ceki G&uuml;lc&uuml;
*/
@ -49,151 +49,119 @@ public class NOPLogger implements Logger {
public final static NOPLogger NOP_LOGGER = new NOPLogger();
/**
* There is no point in creating multiple instances of NullLogger.
* Hence, the private access modifier.
* There is no point in creating multiple instances of NullLogger,
* hence the private access modifier.
*/
private NOPLogger() {
}
/* Always returns false.
*
* @see org.slf4j.Logger#isDebugEnabled()
/**
* Always returns false.
* @return always false
*/
public boolean isDebugEnabled() {
return false;
}
/* A NOP implementation.
* @see org.slf4j.Logger#debug(java.lang.Object)
*/
public void debug(Object msg) {
/** A NOP implementation. */
public void debug(String msg) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#debug(java.lang.Object, java.lang.Object)
*/
public void debug(Object parameterizedMsg, Object param1) {
/** A NOP implementation. */
public void debug(String format, Object arg) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#debug(java.lang.Object, java.lang.Object, java.lang.Object)
*/
public void debug(String parameterizedMsg, Object param1, Object param2) {
/** A NOP implementation. */
public void debug(String format, Object arg1, Object arg2) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#debug(java.lang.Object, java.lang.Throwable)
*/
public void debug(Object msg, Throwable t) {
/** A NOP implementation. */
public void debug(String msg, Throwable t) {
// NOP
}
/* Always returns false.
* @see org.slf4j.Logger#isInfoEnabled()
/**
* Always returns false.
* @return always false
*/
public boolean isInfoEnabled() {
// NOP
return false;
}
/* A NOP implementation.
* @see org.slf4j.Logger#info(java.lang.Object)
*/
public void info(Object msg) {
/** A NOP implementation. */
public void info(String msg) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#info(java.lang.Object, java.lang.Object)
*/
public void info(Object parameterizedMsg, Object param1) {
/** A NOP implementation. */
public void info(String format, Object arg1) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#info(java.lang.Object, java.lang.Object, java.lang.Object)
*/
public void info(String parameterizedMsg, Object param1, Object param2) {
/** A NOP implementation. */
public void info(String format, Object arg1, Object arg2) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#info(java.lang.Object, java.lang.Throwable)
*/
public void info(Object msg, Throwable t) {
/** A NOP implementation. */
public void info(String msg, Throwable t) {
// NOP
}
/* Always returns false.
* @see org.slf4j.Logger#isWarnEnabled()
/**
* Always returns false.
* @return always false
*/
public boolean isWarnEnabled() {
return false;
}
/* A NOP implementation.
* @see org.slf4j.Logger#warn(java.lang.Object)
*/
public void warn(Object msg) {
/** A NOP implementation. */
public void warn(String msg) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#warn(java.lang.Object, java.lang.Object)
*/
public void warn(Object parameterizedMsg, Object param1) {
/** A NOP implementation. */
public void warn(String format, Object arg1) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#warn(java.lang.Object, java.lang.Object, java.lang.Object)
*/
public void warn(String parameterizedMsg, Object param1, Object param2) {
/** A NOP implementation. */
public void warn(String format, Object arg1, Object arg2) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#warn(java.lang.Object, java.lang.Throwable)
*/
public void warn(Object msg, Throwable t) {
/** A NOP implementation. */
public void warn(String msg, Throwable t) {
// NOP
}
/* Always returns false.
* @see org.slf4j.Logger#isErrorEnabled()
*/
/** A NOP implementation. */
public boolean isErrorEnabled() {
return false;
}
/* A NOP implementation.
* @see org.slf4j.Logger#error(java.lang.Object)
*/
public void error(Object msg) {
/** A NOP implementation. */
public void error(String msg) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#error(java.lang.Object, java.lang.Object)
*/
public void error(Object parameterizedMsg, Object param1) {
/** A NOP implementation. */
public void error(String format, Object arg1) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#error(java.lang.Object, java.lang.Object, java.lang.Object)
*/
public void error(String parameterizedMsg, Object param1, Object param2) {
/** A NOP implementation. */
public void error(String format, Object arg1, Object arg2) {
// NOP
}
/* A NOP implementation.
* @see org.slf4j.Logger#error(java.lang.Object, java.lang.Throwable)
*/
public void error(Object msg, Throwable t) {
/** A NOP implementation. */
public void error(String msg, Throwable t) {
// NOP
}

View File

@ -38,8 +38,9 @@ import org.slf4j.Logger;
/**
* NOPLoggerFA is am implementation of {@link LoggerFactoryAdapter}
* which always returns the unique instance of NOPLogger.
* NOPLoggerFA is an trivial implementation of {@link
* LoggerFactoryAdapter} which always returns the unique instance of
* NOPLogger.
*
* @author Ceki Gulcu
*/

View File

@ -37,20 +37,23 @@ import org.slf4j.Logger;
/**
* A simple implementation that logs messages of level INFO or higher on
* the console (<code>System.out<code>).
* <p>
* The output includes the relative time in milliseconds, thread name, the level,
* logger name, and the message followed by the line separator for the host.
* In log4j terms it amounts to the "%r [%t] %level %logger - %m%n" pattern.
* A simple (and direct) implementation that logs messages of level
* INFO or higher on the console (<code>System.out<code>).
*
* <p>The output includes the relative time in milliseconds, thread
* name, the level, logger name, and the message followed by the line
* separator for the host. In log4j terms it amounts to the "%r [%t]
* %level %logger - %m%n" pattern. *</p>
*
* <p>Sample output follows.</p>
* <pre>
176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse order.
225 [main] INFO examples.SortAlgo - Entered the sort method.
304 [main] INFO SortAlgo.DUMP - Dump of interger array:
317 [main] INFO SortAlgo.DUMP - Element [0] = 0
331 [main] INFO SortAlgo.DUMP - Element [1] = 1
304 [main] INFO examples.SortAlgo - Dump of interger array:
317 [main] INFO examples.SortAlgo - Element [0] = 0
331 [main] INFO examples.SortAlgo - Element [1] = 1
343 [main] INFO examples.Sort - The next log statement should be an error message.
346 [main] ERROR SortAlgo.DUMP - Tried to dump an uninitialized array.
346 [main] ERROR examples.SortAlgo - Tried to dump an uninitialized array.
at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
at org.log4j.examples.Sort.main(Sort.java:64)
467 [main] INFO examples.Sort - Exiting main method.
@ -83,36 +86,41 @@ public class SimpleLogger implements Logger {
/**
* Always returns false.
* @return always false
*/
public boolean isDebugEnabled() {
return false;
}
/**
* A NOP implementation.
/**
* A NOP implementation, as this logger is permanently disabled for
* the DEBUG level.
*/
public void debug(Object msg) {
public void debug(String msg) {
// NOP
}
/**
* A NOP implementation.
/**
* A NOP implementation, as this logger is permanently disabled for
* the DEBUG level.
*/
public void debug(Object parameterizedMsg, Object param1) {
public void debug(String format, Object param1) {
// NOP
}
/**
* A NOP implementation.
/**
* A NOP implementation, as this logger is permanently disabled for
* the DEBUG level.
*/
public void debug(String parameterizedMsg, Object param1, Object param2) {
public void debug(String format, Object param1, Object param2) {
// NOP
}
/**
* A NOP implementation.
/**
* A NOP implementation, as this logger is permanently disabled for
* the DEBUG level.
*/
public void debug(Object msg, Throwable t) {
public void debug(String msg, Throwable t) {
// NOP
}
@ -150,24 +158,18 @@ public class SimpleLogger implements Logger {
}
System.out.flush();
}
/**
* For parameterized messages, first substitute parameters and then log.
* For formatted messages, first substitute arguments and then log.
*
* @param level
* @param parameterizedMsg
* @param format
* @param param1
* @param param2
*/
private void parameterizedLog(String level, Object parameterizedMsg, Object param1, Object param2) {
if (parameterizedMsg instanceof String) {
String msgStr = (String) parameterizedMsg;
msgStr = MessageFormatter.format(msgStr, param1, param2);
log(level, msgStr, null);
} else {
// To be failsafe, we handle the case where 'messagePattern' is not
// a String. Unless the user makes a mistake, this should not happen.
log(level, parameterizedMsg.toString(), null);
}
private void formatAndLog(String level, String format, Object arg1, Object arg2) {
String message = MessageFormatter.format(format, arg1, arg2);
log(level, message, null);
}
/**
@ -181,8 +183,8 @@ public class SimpleLogger implements Logger {
* A simple implementation which always logs messages of level INFO according
* to the format outlined above.
*/
public void info(Object msg) {
log(INFO_STR, msg.toString(), null);
public void info(String msg) {
log(INFO_STR, msg, null);
}
@ -190,8 +192,8 @@ public class SimpleLogger implements Logger {
* Perform single parameter substituion before logging the message of level
* INFO according to the format outlined above.
*/
public void info(Object parameterizedMsg, Object param1) {
parameterizedLog(INFO_STR, parameterizedMsg, param1, null);
public void info(String format, Object arg) {
formatAndLog(INFO_STR, format, arg, null);
}
/**
@ -199,14 +201,14 @@ public class SimpleLogger implements Logger {
* INFO according to the format outlined above.
*/
public void info(String parameterizedMsg, Object param1, Object param2) {
parameterizedLog(INFO_STR, parameterizedMsg, param1, param2);
public void info(String format, Object arg1, Object arg2) {
formatAndLog(INFO_STR, format, arg1, arg2);
}
/**
* Log a message of level INFO, including an exception.
*/
public void info(Object msg, Throwable t) {
public void info(String msg, Throwable t) {
log(INFO_STR, msg.toString(), t);
}
@ -221,7 +223,7 @@ public class SimpleLogger implements Logger {
* A simple implementation which always logs messages of level WARN according
* to the format outlined above.
*/
public void warn(Object msg) {
public void warn(String msg) {
log(WARN_STR, msg.toString(), null);
}
@ -229,22 +231,22 @@ public class SimpleLogger implements Logger {
* Perform single parameter substituion before logging the message of level
* WARN according to the format outlined above.
*/
public void warn(Object parameterizedMsg, Object param1) {
parameterizedLog(WARN_STR, parameterizedMsg, param1, null);
public void warn(String format, Object arg) {
formatAndLog(WARN_STR, format, arg, null);
}
/**
* Perform double parameter substituion before logging the message of level
* WARN according to the format outlined above.
*/
public void warn(String parameterizedMsg, Object param1, Object param2) {
parameterizedLog(WARN_STR, parameterizedMsg, param1, param2);
public void warn(String format, Object arg1, Object arg2) {
formatAndLog(WARN_STR, format, arg1, arg2);
}
/**
* Log a message of level WARN, including an exception.
*/
public void warn(Object msg, Throwable t) {
public void warn(String msg, Throwable t) {
log(WARN_STR, msg.toString(), t);
}
@ -259,7 +261,7 @@ public class SimpleLogger implements Logger {
* A simple implementation which always logs messages of level ERROR acoording
* to the format outlined above.
*/
public void error(Object msg) {
public void error(String msg) {
log(ERROR_STR, msg.toString(), null);
}
@ -268,22 +270,22 @@ public class SimpleLogger implements Logger {
* Perform single parameter substituion before logging the message of level
* ERROR according to the format outlined above.
*/
public void error(Object parameterizedMsg, Object param1) {
parameterizedLog(ERROR_STR, parameterizedMsg, param1, null);
public void error(String format, Object arg) {
formatAndLog(ERROR_STR, format, arg, null);
}
/**
* Perform double parameter substituion before logging the message of level
* ERROR according to the format outlined above.
*/
public void error(String parameterizedMsg, Object param1, Object param2) {
parameterizedLog(ERROR_STR, parameterizedMsg, param1, param2);
public void error(String format, Object arg1, Object arg2) {
formatAndLog(ERROR_STR, format, arg1, arg2);
}
/**
* Log a message of level ERROR, including an exception.
*/
public void error(Object msg, Throwable t) {
public void error(String msg, Throwable t) {
log(ERROR_STR, msg.toString(), t);
}