com.samskivert.util
Class Logger

java.lang.Object
  extended by com.samskivert.util.Logger
Direct Known Subclasses:
JDK14Logger.Impl, Log4JLogger.Impl

public abstract class Logger
extends Object

Provides logging services to this library and others which depend on this library in such a way that they can be used in a larger project and easily be made to log to the logging framework in use by that project.

The default implementation uses log4j if it is available and falls back to the Java logging services if not. A specific (or custom) logging implementation can be configured like so:

-Dcom.samskivert.util.Logger=com.samskivert.util.Log4Logger

One additional enhancement is the use of varargs log methods to allow for some handy automatic formatting. The methods take a log message and list of zero or more additional parameters. Those parameters should be key/value pairs which will be logged like so:

message [key=value, key=value, key=value]

The final parameter can optionally be a Throwable, which will be supplied to the underlying log system as an exception to accompany the log message.


Nested Class Summary
static interface Logger.Factory
          Used to create logger instances.
 
Field Summary
protected static Logger.Factory _factory
           
 
Constructor Summary
Logger()
           
 
Method Summary
protected static Logger.Factory createConfiguredFactory()
          A helper function for initLogger().
abstract  void debug(Object message, Object... args)
          Logs a debug message.
abstract  void error(Object message, Object... args)
          Logs an error message.
protected  String format(Object message, Object[] args)
          Format messages and arguments.
protected  Throwable getException(Object message, Object[] args)
          Extracts the exception from the message and arguments (if there is one).
static Logger getLogger(Class<?> clazz)
          Obtains a logger with a name equal to the supplied class's name.
static Logger getLogger(String name)
          Obtains a logger with the specified name.
abstract  void info(Object message, Object... args)
          Logs an info message.
protected static void initLogger()
          Called at static initialization time.
static void setFactory(Logger.Factory factory)
          Configures the logging factory be used by the logging system.
abstract  void warning(Object message, Object... args)
          Logs a warning message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_factory

protected static Logger.Factory _factory
Constructor Detail

Logger

public Logger()
Method Detail

getLogger

public static Logger getLogger(String name)
Obtains a logger with the specified name.


getLogger

public static Logger getLogger(Class<?> clazz)
Obtains a logger with a name equal to the supplied class's name.


setFactory

public static void setFactory(Logger.Factory factory)
Configures the logging factory be used by the logging system. Normally you would not do this and would instead use the com.samskivert.util.Logger system property instead, but in some situations, like in an applet, you cannot pass system properties and we can't read them anyway because we're running in a security sandbox.


debug

public abstract void debug(Object message,
                           Object... args)
Logs a debug message.

Parameters:
message - the message to be logged.
args - a list of key/value pairs and an optional final Throwable.

info

public abstract void info(Object message,
                          Object... args)
Logs an info message.

Parameters:
message - the message to be logged.
args - a list of key/value pairs and an optional final Throwable.

warning

public abstract void warning(Object message,
                             Object... args)
Logs a warning message.

Parameters:
message - the message to be logged.
args - a list of key/value pairs and an optional final Throwable.

error

public abstract void error(Object message,
                           Object... args)
Logs an error message.

Parameters:
message - the message to be logged.
args - a list of key/value pairs and an optional final Throwable.

format

protected String format(Object message,
                        Object[] args)
Format messages and arguments. For use by logger implementations.


getException

protected Throwable getException(Object message,
                                 Object[] args)
Extracts the exception from the message and arguments (if there is one). For use by logger implementations.


initLogger

protected static void initLogger()
Called at static initialization time. Selects and initializes our logging backend.


createConfiguredFactory

protected static Logger.Factory createConfiguredFactory()
A helper function for initLogger().



Copyright © 2000-2008 Michael Bayne. All Rights Reserved.