Simple Log 2.0.1
[grlea]

org.grlea.log.adapters.commons
Class CommonsLoggingAdapter

java.lang.Object
  extended byorg.grlea.log.adapters.commons.CommonsLoggingAdapter
All Implemented Interfaces:
Log

public class CommonsLoggingAdapter
extends java.lang.Object
implements Log

An adapter for using Simple Log within the Jakarta Commons Logging package.

Instructions for Use

To use this CommonsLoggingAdapter with Commons Logging, simply set the system property 'org.apache.commons.logging.Log' to 'org.grlea.log.adapters.commons.CommonsLoggingAdapter'.

Implementation Details

The CommonsLoggingAdapter always uses the default SimpleLog. It is anticipated this will do the job for the preverbial 99% of cases. If this is insufficient for your needs, please write to me and we can try and find a more flexible solution.

The Commons Logging levels are mapped to the Simple Log levels in this manner:

Commons Logging Simple Log
Fatal Fatal
Error Error
Warn Warn
Info Info
Debug Debug
Trace Verbose

"Tracing"

Note that the Commons Logging 'Trace' level is not matched to Simple Log's tracing facility (i.e. SimpleLogger's entry() and exit() methdos), but to the Verbose level. This is because the Commons Logging API allows any kind of object or exception to be logged at the Trace level (rather than just method names), and provides no information regarding whether the log is for a method entry or exit.

Logger Names

The Commons Logging API provides logger names that are Strings, while Simple Log prefers Class objects for naming its loggers. This adapter tries to rectify the discord by attempting to interpret logger names as fully qualified class names. Where this is not possible (because the logger name is not a class name), a SimpleLogger will be created using a source class of org.apache.commons.logging.Log and with the provided logger name as the instance ID of the logger. (See SimpleLogger.SimpleLogger(Class, Object). This means that, when writing properties to configure loggers that don't use class names, the properties should take the form:

    org.apache.commons.logging.Log.<logger-name>

When logger names cannot be interpreted as class names, each logger name that cannot be interpreted will be printed with a warning to System.err. You can supress these warnings by setting the system property org.grlea.log.adapters.commons.supressWarnings to true.

Object Rendering

Because Simple Log has a notion of logging message types (i.e. debug message, debug object and debug exception) but Commons Logging does not, the generic 'message' objects passed in to this adapter are passed on to Simple Log in this manner:

Version:
$Revision: 1.2 $
Author:
Graham Lea

Constructor Summary
CommonsLoggingAdapter(java.lang.String loggerName)
           
 
Method Summary
 void debug(java.lang.Object message)
           
 void debug(java.lang.Object message, java.lang.Throwable t)
           
 void error(java.lang.Object message)
           
 void error(java.lang.Object message, java.lang.Throwable t)
           
 void fatal(java.lang.Object message)
           
 void fatal(java.lang.Object message, java.lang.Throwable t)
           
 void info(java.lang.Object message)
           
 void info(java.lang.Object message, java.lang.Throwable t)
           
 boolean isDebugEnabled()
           
 boolean isErrorEnabled()
           
 boolean isFatalEnabled()
           
 boolean isInfoEnabled()
           
 boolean isTraceEnabled()
           
 boolean isWarnEnabled()
           
static void setLog(SimpleLog simpleLog)
           
 void trace(java.lang.Object message)
           
 void trace(java.lang.Object message, java.lang.Throwable t)
           
 void warn(java.lang.Object message)
           
 void warn(java.lang.Object message, java.lang.Throwable t)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CommonsLoggingAdapter

public CommonsLoggingAdapter(java.lang.String loggerName)
Method Detail

setLog

public static void setLog(SimpleLog simpleLog)

isFatalEnabled

public boolean isFatalEnabled()
Specified by:
isFatalEnabled in interface Log

isErrorEnabled

public boolean isErrorEnabled()
Specified by:
isErrorEnabled in interface Log

isWarnEnabled

public boolean isWarnEnabled()
Specified by:
isWarnEnabled in interface Log

isInfoEnabled

public boolean isInfoEnabled()
Specified by:
isInfoEnabled in interface Log

isDebugEnabled

public boolean isDebugEnabled()
Specified by:
isDebugEnabled in interface Log

isTraceEnabled

public boolean isTraceEnabled()
Specified by:
isTraceEnabled in interface Log

fatal

public void fatal(java.lang.Object message)
Specified by:
fatal in interface Log

fatal

public void fatal(java.lang.Object message,
                  java.lang.Throwable t)
Specified by:
fatal in interface Log

error

public void error(java.lang.Object message)
Specified by:
error in interface Log

error

public void error(java.lang.Object message,
                  java.lang.Throwable t)
Specified by:
error in interface Log

warn

public void warn(java.lang.Object message)
Specified by:
warn in interface Log

warn

public void warn(java.lang.Object message,
                 java.lang.Throwable t)
Specified by:
warn in interface Log

info

public void info(java.lang.Object message)
Specified by:
info in interface Log

info

public void info(java.lang.Object message,
                 java.lang.Throwable t)
Specified by:
info in interface Log

debug

public void debug(java.lang.Object message)
Specified by:
debug in interface Log

debug

public void debug(java.lang.Object message,
                  java.lang.Throwable t)
Specified by:
debug in interface Log

trace

public void trace(java.lang.Object message)
Specified by:
trace in interface Log

trace

public void trace(java.lang.Object message,
                  java.lang.Throwable t)
Specified by:
trace in interface Log

Copyright (c) 2004-2006, Graham Lea. All rights reserved.