Simple Log 2.0.1
[grlea]

org.grlea.log.adapters.slf4j
Class Slf4jAdapter

java.lang.Object
  extended byorg.slf4j.impl.MarkerIgnoringBase
      extended byorg.grlea.log.adapters.slf4j.Slf4jAdapter
All Implemented Interfaces:
Logger

public class Slf4jAdapter
extends MarkerIgnoringBase

An adapter for using Simple Log within the SLF4J package.

Instructions for Use

To use this Slf4jAdapter with SLF4J, you should only need to include the JARs for Simple Log (simple-log.jar) and for the SLF4J Adapter (simple-log-slf4j.jar) in your classpath and use the SLF4J LoggerFactory to obtain log instances. Be careful not to confuse 'slf4j-simple.jar' as being part of the arrangement. It is a SLF4J deliverable that simply prints output to System.out.

Implementation Details

The Slf4jAdapter 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 SLF4J levels map directly to the Simple Log levels:

SLF4J Simple Log
Error Error
Warn Warn
Info Info
Debug Debug

"Tracing"

Note that the SLF4J has no notion of tracing whatsoever, so the tracing properties in Simple Log will have no bearing on the output.

Logger Names

The SLF4J 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.slf4j.Logger and with the provided logger name as the instance ID of the logger. (See SimpleLogger.SimpleLogger(Class, Object). When the two-argument domain + sub-domain method is used and the domain is not a fully-qualified class name, the domain and sub-domain are concatenated with a period ('.') in between, e.g. "domain.subdomain", and this is used as the instance ID. This means that, when writing properties to configure loggers that don't use class names, the properties should take the form:

    org.slf4j.Logger.<logger-name>
or
    org.slf4j.Logger.<domain>.<subdomain>

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.slf4j.supressWarnings to true.

Object Rendering

Messages submitted to the Slf4jAdapter using the format + argument(s) methods are interpreted using the MessageFormatter that is provided in SLF4J.

Version:
$Revision: 1.2 $
Author:
Graham Lea

Method Summary
 void debug(java.lang.String message)
          Log a message at the DEBUG level.
 void debug(java.lang.String messageFormat, java.lang.Object argument)
          Log a message at the DEBUG level according to the specified format and argument.
 void debug(java.lang.String messageFormat, java.lang.Object[] arguments)
          Log a message at the DEBUG level according to the specified format and arguments.
 void debug(java.lang.String messageFormat, java.lang.Object argument1, java.lang.Object argument2)
          Log a message at the DEBUG level according to the specified format and arguments.
 void debug(java.lang.String message, java.lang.Throwable exception)
          Log an exception (throwable) at the DEBUG level with an accompanying message.
 void error(java.lang.String message)
          Log a message at the ERROR level.
 void error(java.lang.String messageFormat, java.lang.Object argument)
          Log a message at the ERROR level according to the specified format and argument.
 void error(java.lang.String messageFormat, java.lang.Object[] arguments)
          Log a message at the ERROR level according to the specified format and arguments.
 void error(java.lang.String messageFormat, java.lang.Object argument1, java.lang.Object argument2)
          Log a message at the ERROR level according to the specified format and arguments.
 void error(java.lang.String message, java.lang.Throwable exception)
          Log an exception (throwable) at the ERROR level with an accompanying message.
 java.lang.String getName()
          Return the name of this Logger instance.
 void info(java.lang.String message)
          Log a message at the INFO level.
 void info(java.lang.String messageFormat, java.lang.Object argument)
          Log a message at the INFO level according to the specified format and argument.
 void info(java.lang.String messageFormat, java.lang.Object[] arguments)
          Log a message at the INFO level according to the specified format and arguments.
 void info(java.lang.String messageFormat, java.lang.Object argument1, java.lang.Object argument2)
          Log a message at the INFO level according to the specified format and arguments.
 void info(java.lang.String message, java.lang.Throwable exception)
          Log an exception (throwable) at the INFO level with an accompanying message.
 boolean isDebugEnabled()
          Is the logger instance enabled for the DEBUG level?
 boolean isErrorEnabled()
          Is the logger instance enabled for the ERROR level?
 boolean isInfoEnabled()
          Is the logger instance enabled for the INFO level?
 boolean isWarnEnabled()
          Is the logger instance enabled for the WARN level?
 void warn(java.lang.String message)
          Log a message at the WARN level.
 void warn(java.lang.String messageFormat, java.lang.Object argument)
          Log a message at the WARN level according to the specified format and argument.
 void warn(java.lang.String messageFormat, java.lang.Object[] arguments)
          Log a message at the WARN level according to the specified format and arguments.
 void warn(java.lang.String messageFormat, java.lang.Object argument1, java.lang.Object argument2)
          Log a message at the WARN level according to the specified format and arguments.
 void warn(java.lang.String message, java.lang.Throwable exception)
          Log an exception (throwable) at the WARN level with an accompanying message.
 
Methods inherited from class org.slf4j.impl.MarkerIgnoringBase
debug, debug, debug, debug, debug, error, error, error, error, error, info, info, info, info, info, isDebugEnabled, isErrorEnabled, isInfoEnabled, isWarnEnabled, warn, warn, warn, warn, warn
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getName

public java.lang.String getName()
Description copied from interface: Logger
Return the name of this Logger instance.


isErrorEnabled

public boolean isErrorEnabled()
Description copied from interface: Logger
Is the logger instance enabled for the ERROR level?

Returns:
True if this Logger is enabled for the ERROR level, false otherwise.

isWarnEnabled

public boolean isWarnEnabled()
Description copied from interface: Logger
Is the logger instance enabled for the WARN level?

Returns:
True if this Logger is enabled for the WARN level, false otherwise.

isInfoEnabled

public boolean isInfoEnabled()
Description copied from interface: Logger
Is the logger instance enabled for the INFO level?

Returns:
True if this Logger is enabled for the INFO level, false otherwise.

isDebugEnabled

public boolean isDebugEnabled()
Description copied from interface: Logger
Is the logger instance enabled for the DEBUG level?

Returns:
True if this Logger is enabled for the DEBUG level, false otherwise.

error

public void error(java.lang.String message)
Description copied from interface: Logger
Log a message at the ERROR level.

Parameters:
message - the message string to be logged

error

public void error(java.lang.String messageFormat,
                  java.lang.Object argument)
Description copied from interface: Logger
Log a message at the ERROR level according to the specified format and argument.

This form avoids superfluous object creation when the logger is disabled for the ERROR level.

Parameters:
messageFormat - the format string
argument - the argument

error

public void error(java.lang.String messageFormat,
                  java.lang.Object argument1,
                  java.lang.Object argument2)
Description copied from interface: Logger
Log a message at the ERROR level according to the specified format and arguments.

This form avoids superfluous object creation when the logger is disabled for the ERROR level.

Parameters:
messageFormat - the format string
argument1 - the first argument
argument2 - the second argument

error

public void error(java.lang.String messageFormat,
                  java.lang.Object[] arguments)
Description copied from interface: Logger
Log a message at the ERROR level according to the specified format and arguments.

This form avoids superfluous object creation when the logger is disabled for the ERROR level.

Parameters:
messageFormat - the format string
arguments - an array of arguments

error

public void error(java.lang.String message,
                  java.lang.Throwable exception)
Description copied from interface: Logger
Log an exception (throwable) at the ERROR level with an accompanying message.

Parameters:
message - the message accompanying the exception
exception - the exception (throwable) to log

warn

public void warn(java.lang.String message)
Description copied from interface: Logger
Log a message at the WARN level.

Parameters:
message - the message string to be logged

warn

public void warn(java.lang.String messageFormat,
                 java.lang.Object argument)
Description copied from interface: Logger
Log a message at the WARN level according to the specified format and argument.

This form avoids superfluous object creation when the logger is disabled for the WARN level.

Parameters:
messageFormat - the format string
argument - the argument

warn

public void warn(java.lang.String messageFormat,
                 java.lang.Object argument1,
                 java.lang.Object argument2)
Description copied from interface: Logger
Log a message at the WARN level according to the specified format and arguments.

This form avoids superfluous object creation when the logger is disabled for the WARN level.

Parameters:
messageFormat - the format string
argument1 - the first argument
argument2 - the second argument

warn

public void warn(java.lang.String messageFormat,
                 java.lang.Object[] arguments)
Description copied from interface: Logger
Log a message at the WARN level according to the specified format and arguments.

This form avoids superfluous object creation when the logger is disabled for the WARN level.

Parameters:
messageFormat - the format string
arguments - an array of arguments

warn

public void warn(java.lang.String message,
                 java.lang.Throwable exception)
Description copied from interface: Logger
Log an exception (throwable) at the WARN level with an accompanying message.

Parameters:
message - the message accompanying the exception
exception - the exception (throwable) to log

info

public void info(java.lang.String message)
Description copied from interface: Logger
Log a message at the INFO level.

Parameters:
message - the message string to be logged

info

public void info(java.lang.String messageFormat,
                 java.lang.Object argument)
Description copied from interface: Logger
Log a message at the INFO level according to the specified format and argument.

This form avoids superfluous object creation when the logger is disabled for the INFO level.

Parameters:
messageFormat - the format string
argument - the argument

info

public void info(java.lang.String messageFormat,
                 java.lang.Object argument1,
                 java.lang.Object argument2)
Description copied from interface: Logger
Log a message at the INFO level according to the specified format and arguments.

This form avoids superfluous object creation when the logger is disabled for the INFO level.

Parameters:
messageFormat - the format string
argument1 - the first argument
argument2 - the second argument

info

public void info(java.lang.String messageFormat,
                 java.lang.Object[] arguments)
Description copied from interface: Logger
Log a message at the INFO level according to the specified format and arguments.

This form avoids superfluous object creation when the logger is disabled for the INFO level.

Parameters:
messageFormat - the format string
arguments - an array of arguments

info

public void info(java.lang.String message,
                 java.lang.Throwable exception)
Description copied from interface: Logger
Log an exception (throwable) at the INFO level with an accompanying message.

Parameters:
message - the message accompanying the exception
exception - the exception (throwable) to log

debug

public void debug(java.lang.String message)
Description copied from interface: Logger
Log a message at the DEBUG level.

Parameters:
message - the message string to be logged

debug

public void debug(java.lang.String messageFormat,
                  java.lang.Object argument)
Description copied from interface: Logger
Log a message at the DEBUG level according to the specified format and argument.

This form avoids superfluous object creation when the logger is disabled for the DEBUG level.

Parameters:
messageFormat - the format string
argument - the argument

debug

public void debug(java.lang.String messageFormat,
                  java.lang.Object argument1,
                  java.lang.Object argument2)
Description copied from interface: Logger
Log a message at the DEBUG level according to the specified format and arguments.

This form avoids superfluous object creation when the logger is disabled for the DEBUG level.

Parameters:
messageFormat - the format string
argument1 - the first argument
argument2 - the second argument

debug

public void debug(java.lang.String messageFormat,
                  java.lang.Object[] arguments)
Description copied from interface: Logger
Log a message at the DEBUG level according to the specified format and arguments.

This form avoids superfluous object creation when the logger is disabled for the DEBUG level.

Parameters:
messageFormat - the format string
arguments - an array of arguments

debug

public void debug(java.lang.String message,
                  java.lang.Throwable exception)
Description copied from interface: Logger
Log an exception (throwable) at the DEBUG level with an accompanying message.

Parameters:
message - the message accompanying the exception
exception - the exception (throwable) to log

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