org.jboss.logging
Class Logger

java.lang.Object
  extended by org.jboss.logging.Logger
All Implemented Interfaces:
Serializable
Direct Known Subclasses:
DynamicLogger

public class Logger
extends Object
implements Serializable

Logger wrapper that tries to dynamically load a log4j class to determine if log4j is available in the VM. If it is the case, a log4j delegate is built and used. In the contrary, a null logger is used. This class cannot directly reference log4j classes otherwise the JVM will try to load it and make it fail. To set

Only exposes the relevent factory and logging methods.

For JBoss the logging should be done as follows:

Version:
$Revision: 3148 $
Author:
Scott.Stark@jboss.org, Jason Dillon, Sacha Labourey
See Also:
isTraceEnabled(), trace(Object), trace(Object,Throwable), Serialized Form

Field Summary
protected static String LOG4J_PLUGIN_CLASS_NAME
          The default LoggerPlugin implementation is log4j
protected  LoggerPlugin loggerDelegate
          The logger plugin delegate
protected static String PLUGIN_CLASS_PROP
          The system property to look for an externalized LoggerPlugin implementation class
protected static Class<?> pluginClass
          The LoggerPlugin implementation class to use
protected static String pluginClassName
          The class name of the LoggerPlugin implementation class to use
 
Constructor Summary
protected Logger(String name)
          Creates new Logger the given logger name.
 
Method Summary
 void debug(Object message)
          Issue a log msg with a level of DEBUG.
 void debug(Object message, Throwable t)
          Issue a log msg and throwable with a level of DEBUG.
 void debug(String loggerFqcn, Object message, Throwable t)
          Issue a log msg and throwable with a level of DEBUG and a specific logger class name.
 void debugf(String format, Object... params)
          Issue a formatted log message with a level of DEBUG.
 void debugf(Throwable t, String format, Object... params)
          Issue a formatted log message with a level of DEBUG.
 void error(Object message)
          Issue a log msg with a level of ERROR.
 void error(Object message, Throwable t)
          Issue a log msg and throwable with a level of ERROR.
 void error(String loggerFqcn, Object message, Throwable t)
          Issue a log msg and throwable with a level of ERROR and a specific logger class name.
 void errorf(String format, Object... params)
          Issue a formatted log message with a level of ERROR.
 void errorf(Throwable t, String format, Object... params)
          Issue a formatted log message with a level of ERROR.
 void fatal(Object message)
          Issue a log msg with a level of FATAL.
 void fatal(Object message, Throwable t)
          Issue a log msg and throwable with a level of FATAL.
 void fatal(String loggerFqcn, Object message, Throwable t)
          Issue a log msg and throwable with a level of FATAL and a specific logger class name.
 void fatalf(String format, Object... params)
          Issue a formatted log message with a level of FATAL.
 void fatalf(Throwable t, String format, Object... params)
          Issue a formatted log message with a level of FATAL.
protected static LoggerPlugin getDelegatePlugin(String name)
          Get the delegate plugin
static Logger getLogger(Class<?> clazz)
          Create a Logger instance given the logger class.
static Logger getLogger(Class<?> clazz, String suffix)
          Create a Logger instance given the logger class with the given suffix.
static Logger getLogger(String name)
          Create a Logger instance given the logger name.
static Logger getLogger(String name, String suffix)
          Create a Logger instance given the logger name with the given suffix.
 LoggerPlugin getLoggerPlugin()
          Get the logger plugin delegate
 String getName()
          Return the name of this logger.
static String getPluginClassName()
          The LoggerPlugin implementation class name in use
 void info(Object message)
          Issue a log msg with a level of INFO.
 void info(Object message, Throwable t)
          Issue a log msg and throwable with a level of INFO.
 void info(String loggerFqcn, Object message, Throwable t)
          Issue a log msg and throwable with a level of INFO and a specific logger class name.
 void infof(String format, Object... params)
          Issue a formatted log message with a level of INFO.
 void infof(Throwable t, String format, Object... params)
          Issue a formatted log message with a level of INFO.
protected static void init()
          Initialize the LoggerPlugin class to use as the delegate to the logging system.
 boolean isDebugEnabled()
          Deprecated. DEBUG is for low volume logging, you don't need this
 boolean isInfoEnabled()
          Deprecated. INFO is for low volume information, you don't need this
 boolean isTraceEnabled()
          Check to see if the TRACE level is enabled for this logger.
static void setPluginClassName(String pluginClassName)
          Set the LoggerPlugin implementation class name in use
 void trace(Object message)
          Issue a log msg with a level of TRACE.
 void trace(Object message, Throwable t)
          Issue a log msg and throwable with a level of TRACE.
 void trace(String loggerFqcn, Object message, Throwable t)
          Issue a log msg and throwable with a level of TRACE and a specific logger class name.
 void tracef(String format, Object... params)
          Issue a formatted log message with a level of TRACE.
 void tracef(Throwable t, String format, Object... params)
          Issue a formatted log message with a level of TRACE.
 void warn(Object message)
          Issue a log msg with a level of WARN.
 void warn(Object message, Throwable t)
          Issue a log msg and throwable with a level of WARN.
 void warn(String loggerFqcn, Object message, Throwable t)
          Issue a log msg and throwable with a level of WARN and a specific logger class name.
 void warnf(String format, Object... params)
          Issue a formatted log message with a level of WARN.
 void warnf(Throwable t, String format, Object... params)
          Issue a formatted log message with a level of WARN.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLUGIN_CLASS_PROP

protected static String PLUGIN_CLASS_PROP
The system property to look for an externalized LoggerPlugin implementation class


LOG4J_PLUGIN_CLASS_NAME

protected static final String LOG4J_PLUGIN_CLASS_NAME
The default LoggerPlugin implementation is log4j

See Also:
Constant Field Values

pluginClass

protected static Class<?> pluginClass
The LoggerPlugin implementation class to use


pluginClassName

protected static String pluginClassName
The class name of the LoggerPlugin implementation class to use


loggerDelegate

protected transient LoggerPlugin loggerDelegate
The logger plugin delegate

Constructor Detail

Logger

protected Logger(String name)
Creates new Logger the given logger name.

Parameters:
name - the logger name.
Method Detail

getPluginClassName

public static String getPluginClassName()
The LoggerPlugin implementation class name in use

Returns:
LoggerPlugin implementation class name

setPluginClassName

public static void setPluginClassName(String pluginClassName)
Set the LoggerPlugin implementation class name in use

Parameters:
pluginClassName - the LoggerPlugin implementation class name

getName

public String getName()
Return the name of this logger.

Returns:
The name of this logger.

getLoggerPlugin

public LoggerPlugin getLoggerPlugin()
Get the logger plugin delegate

Returns:
the delegate

isTraceEnabled

public boolean isTraceEnabled()
Check to see if the TRACE level is enabled for this logger.

Returns:
true if a trace(Object) method invocation would pass the msg to the configured appenders, false otherwise.

trace

public void trace(Object message)
Issue a log msg with a level of TRACE.

Parameters:
message - the message

trace

public void trace(Object message,
                  Throwable t)
Issue a log msg and throwable with a level of TRACE.

Parameters:
message - the message
t - the throwable

trace

public void trace(String loggerFqcn,
                  Object message,
                  Throwable t)
Issue a log msg and throwable with a level of TRACE and a specific logger class name.

Parameters:
loggerFqcn - the logger class name
message - the message
t - the throwable

tracef

public void tracef(String format,
                   Object... params)
Issue a formatted log message with a level of TRACE.

Parameters:
format - the format string, as per String.format(String, Object[])
params - the parameters

tracef

public void tracef(Throwable t,
                   String format,
                   Object... params)
Issue a formatted log message with a level of TRACE.

Parameters:
t - the throwable
format - the format string, as per String.format(String, Object[])
params - the parameters

isDebugEnabled

public boolean isDebugEnabled()
Deprecated. DEBUG is for low volume logging, you don't need this

Check to see if the DEBUG level is enabled for this logger.

Returns:
true if a trace(Object) method invocation would pass the msg to the configured appenders, false otherwise.

debug

public void debug(Object message)
Issue a log msg with a level of DEBUG.

Parameters:
message - the message

debug

public void debug(Object message,
                  Throwable t)
Issue a log msg and throwable with a level of DEBUG.

Parameters:
message - the message
t - the throwable

debug

public void debug(String loggerFqcn,
                  Object message,
                  Throwable t)
Issue a log msg and throwable with a level of DEBUG and a specific logger class name.

Parameters:
loggerFqcn - the logger class name
message - the message
t - the throwable

debugf

public void debugf(String format,
                   Object... params)
Issue a formatted log message with a level of DEBUG.

Parameters:
format - the format string, as per String.format(String, Object[])
params - the parameters

debugf

public void debugf(Throwable t,
                   String format,
                   Object... params)
Issue a formatted log message with a level of DEBUG.

Parameters:
t - the throwable
format - the format string, as per String.format(String, Object[])
params - the parameters

isInfoEnabled

public boolean isInfoEnabled()
Deprecated. INFO is for low volume information, you don't need this

Check to see if the INFO level is enabled for this logger.

Returns:
true if a info(Object) method invocation would pass the msg to the configured appenders, false otherwise.

info

public void info(Object message)
Issue a log msg with a level of INFO.

Parameters:
message - the message

info

public void info(Object message,
                 Throwable t)
Issue a log msg and throwable with a level of INFO.

Parameters:
message - the message
t - the throwable

info

public void info(String loggerFqcn,
                 Object message,
                 Throwable t)
Issue a log msg and throwable with a level of INFO and a specific logger class name.

Parameters:
loggerFqcn - the logger class name
message - the message
t - the throwable

infof

public void infof(String format,
                  Object... params)
Issue a formatted log message with a level of INFO.

Parameters:
format - the format string, as per String.format(String, Object[])
params - the parameters

infof

public void infof(Throwable t,
                  String format,
                  Object... params)
Issue a formatted log message with a level of INFO.

Parameters:
t - the throwable
format - the format string, as per String.format(String, Object[])
params - the parameters

warn

public void warn(Object message)
Issue a log msg with a level of WARN.

Parameters:
message - the message

warn

public void warn(Object message,
                 Throwable t)
Issue a log msg and throwable with a level of WARN.

Parameters:
message - the message
t - the throwable

warn

public void warn(String loggerFqcn,
                 Object message,
                 Throwable t)
Issue a log msg and throwable with a level of WARN and a specific logger class name.

Parameters:
loggerFqcn - the logger class name
message - the message
t - the throwable

warnf

public void warnf(String format,
                  Object... params)
Issue a formatted log message with a level of WARN.

Parameters:
format - the format string, as per String.format(String, Object[])
params - the parameters

warnf

public void warnf(Throwable t,
                  String format,
                  Object... params)
Issue a formatted log message with a level of WARN.

Parameters:
t - the throwable
format - the format string, as per String.format(String, Object[])
params - the parameters

error

public void error(Object message)
Issue a log msg with a level of ERROR.

Parameters:
message - the message

error

public void error(Object message,
                  Throwable t)
Issue a log msg and throwable with a level of ERROR.

Parameters:
message - the message
t - the throwable

error

public void error(String loggerFqcn,
                  Object message,
                  Throwable t)
Issue a log msg and throwable with a level of ERROR and a specific logger class name.

Parameters:
loggerFqcn - the logger class name
message - the message
t - the throwable

errorf

public void errorf(String format,
                   Object... params)
Issue a formatted log message with a level of ERROR.

Parameters:
format - the format string, as per String.format(String, Object[])
params - the parameters

errorf

public void errorf(Throwable t,
                   String format,
                   Object... params)
Issue a formatted log message with a level of ERROR.

Parameters:
t - the throwable
format - the format string, as per String.format(String, Object[])
params - the parameters

fatal

public void fatal(Object message)
Issue a log msg with a level of FATAL.

Parameters:
message - the message

fatal

public void fatal(Object message,
                  Throwable t)
Issue a log msg and throwable with a level of FATAL.

Parameters:
message - the message
t - the throwable

fatal

public void fatal(String loggerFqcn,
                  Object message,
                  Throwable t)
Issue a log msg and throwable with a level of FATAL and a specific logger class name.

Parameters:
loggerFqcn - the logger class name
message - the message
t - the throwable

fatalf

public void fatalf(String format,
                   Object... params)
Issue a formatted log message with a level of FATAL.

Parameters:
format - the format string, as per String.format(String, Object[])
params - the parameters

fatalf

public void fatalf(Throwable t,
                   String format,
                   Object... params)
Issue a formatted log message with a level of FATAL.

Parameters:
t - the throwable
format - the format string, as per String.format(String, Object[])
params - the parameters

getLogger

public static Logger getLogger(String name)
Create a Logger instance given the logger name.

Parameters:
name - the logger name
Returns:
the logger

getLogger

public static Logger getLogger(String name,
                               String suffix)
Create a Logger instance given the logger name with the given suffix.

This will include a logger seperator between classname and suffix

Parameters:
name - the logger name
suffix - a suffix to append to the classname.
Returns:
the logger

getLogger

public static Logger getLogger(Class<?> clazz)
Create a Logger instance given the logger class. This simply calls create(clazz.getName()).

Parameters:
clazz - the Class whose name will be used as the logger name
Returns:
the logger

getLogger

public static Logger getLogger(Class<?> clazz,
                               String suffix)
Create a Logger instance given the logger class with the given suffix.

This will include a logger seperator between classname and suffix

Parameters:
clazz - the Class whose name will be used as the logger name.
suffix - a suffix to append to the classname.
Returns:
the logger

getDelegatePlugin

protected static LoggerPlugin getDelegatePlugin(String name)
Get the delegate plugin

Parameters:
name - the name of the logger
Returns:
the plugin

init

protected static void init()
Initialize the LoggerPlugin class to use as the delegate to the logging system. This first checks to see if a pluginClassName has been specified via the setPluginClassName(String) method, then the PLUGIN_CLASS_PROP system property and finally the LOG4J_PLUGIN_CLASS_NAME default. If the LoggerPlugin implementation class cannot be loaded the default NullLoggerPlugin will be used.



Copyright © 2009 JBoss Inc.. All Rights Reserved.