org.modeshape.common.util
Class Logger

java.lang.Object
  extended by org.modeshape.common.util.Logger

@ThreadSafe
public final class Logger
extends Object

A simple logging interface that is fully compatible with multiple logging implementations. This interface does take advantage of the variable arguments and autoboxing features in Java 5, reducing the number of methods that are necessary and allowing callers to supply primitive values as parameters.


Nested Class Summary
static class Logger.Level
           
 
Method Summary
 void debug(String message, Object... params)
          Log a message at the DEBUG level according to the specified format and (optional) parameters.
 void debug(Throwable t, String message, Object... params)
          Log an exception (throwable) at the DEBUG level with an accompanying message.
 void error(I18n message, Object... params)
          Log a message at the ERROR level according to the specified format and (optional) parameters.
 void error(Throwable t, I18n message, Object... params)
          Log an exception (throwable) at the ERROR level with an accompanying message.
 Logger.Level getLevel()
          Get the logging level at which this logger is current set.
static Logger getLogger(Class<?> clazz)
          Return a logger named corresponding to the class passed as parameter, using the statically bound ILoggerFactory instance.
static Logger getLogger(String name)
          Return a logger named according to the name parameter using the statically bound ILoggerFactory instance.
static Locale getLoggingLocale()
          Get the locale used for the logs.
 String getName()
          Return the name of this logger instance.
 void info(I18n message, Object... params)
          Log a message at the INFO level according to the specified format and (optional) parameters.
 void info(Throwable t, I18n message, Object... params)
          Log an exception (throwable) at the INFO level with an accompanying message.
 boolean isDebugEnabled()
          Return whether messages at the DEBUG level are being logged.
 boolean isTraceEnabled()
          Return whether messages at the TRACE level are being logged.
 void log(Logger.Level level, I18n message, Object... params)
          Log a message at the suplied level according to the specified format and (optional) parameters.
 void log(Logger.Level level, Throwable t, I18n message, Object... params)
          Log an exception (throwable) at the supplied level with an accompanying message.
static Locale setLoggingLocale(Locale locale)
          Set the locale used for the logs.
 void trace(String message, Object... params)
          Log a message at the TRACE level according to the specified format and (optional) parameters.
 void trace(Throwable t, String message, Object... params)
          Log an exception (throwable) at the TRACE level with an accompanying message.
 void warn(I18n message, Object... params)
          Log a message at the WARNING level according to the specified format and (optional) parameters.
 void warn(Throwable t, I18n message, Object... params)
          Log an exception (throwable) at the WARNING level with an accompanying message.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getLoggingLocale

public static Locale getLoggingLocale()
Get the locale used for the logs. If null, the default locale is used.

Returns:
the current locale used for logging, or null if the system locale is used
See Also:
setLoggingLocale(Locale)

setLoggingLocale

public static Locale setLoggingLocale(Locale locale)
Set the locale used for the logs. This should be used when the logs are to be written is a specific locale, independent of the default locale. To use the default locale, call this method with a null value.

Parameters:
locale - the desired locale to use for the logs, or null if the system locale should be used
Returns:
the previous locale
See Also:
getLoggingLocale()

getLogger

public static Logger getLogger(Class<?> clazz)
Return a logger named corresponding to the class passed as parameter, using the statically bound ILoggerFactory instance.

Parameters:
clazz - the returned logger will be named after clazz
Returns:
logger

getLogger

public static Logger getLogger(String name)
Return a logger named according to the name parameter using the statically bound ILoggerFactory instance.

Parameters:
name - The name of the logger.
Returns:
logger

getName

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

Returns:
the logger's name

log

public void log(Logger.Level level,
                I18n message,
                Object... params)
Log a message at the suplied level according to the specified format and (optional) parameters. The message should contain a pair of empty curly braces for each of the parameter, which should be passed in the correct order. This method is efficient and avoids superfluous object creation when the logger is disabled for the desired level.

Parameters:
level - the level at which to log
message - the (localized) message string
params - the parameter values that are to replace the variables in the format string

log

public void log(Logger.Level level,
                Throwable t,
                I18n message,
                Object... params)
Log an exception (throwable) at the supplied level with an accompanying message. If the exception is null, then this method calls debug(String, Object...).

Parameters:
level - the level at which to log
t - the exception (throwable) to log
message - the message accompanying the exception
params - the parameter values that are to replace the variables in the format string

debug

public void debug(String message,
                  Object... params)
Log a message at the DEBUG level according to the specified format and (optional) parameters. The message should contain a pair of empty curly braces for each of the parameter, which should be passed in the correct order. This method is efficient and avoids superfluous object creation when the logger is disabled for the DEBUG level.

Parameters:
message - the message string
params - the parameter values that are to replace the variables in the format string

debug

public void debug(Throwable t,
                  String message,
                  Object... params)
Log an exception (throwable) at the DEBUG level with an accompanying message. If the exception is null, then this method calls debug(String, Object...).

Parameters:
t - the exception (throwable) to log
message - the message accompanying the exception
params - the parameter values that are to replace the variables in the format string

error

public void error(I18n message,
                  Object... params)
Log a message at the ERROR level according to the specified format and (optional) parameters. The message should contain a pair of empty curly braces for each of the parameter, which should be passed in the correct order. This method is efficient and avoids superfluous object creation when the logger is disabled for the ERROR level.

Parameters:
message - the message string
params - the parameter values that are to replace the variables in the format string

error

public void error(Throwable t,
                  I18n message,
                  Object... params)
Log an exception (throwable) at the ERROR level with an accompanying message. If the exception is null, then this method calls error(I18n, Object...).

Parameters:
t - the exception (throwable) to log
message - the message accompanying the exception
params - the parameter values that are to replace the variables in the format string

info

public void info(I18n message,
                 Object... params)
Log a message at the INFO level according to the specified format and (optional) parameters. The message should contain a pair of empty curly braces for each of the parameter, which should be passed in the correct order. This method is efficient and avoids superfluous object creation when the logger is disabled for the INFO level.

Parameters:
message - the message string
params - the parameter values that are to replace the variables in the format string

info

public void info(Throwable t,
                 I18n message,
                 Object... params)
Log an exception (throwable) at the INFO level with an accompanying message. If the exception is null, then this method calls info(I18n, Object...).

Parameters:
t - the exception (throwable) to log
message - the message accompanying the exception
params - the parameter values that are to replace the variables in the format string

trace

public void trace(String message,
                  Object... params)
Log a message at the TRACE level according to the specified format and (optional) parameters. The message should contain a pair of empty curly braces for each of the parameter, which should be passed in the correct order. This method is efficient and avoids superfluous object creation when the logger is disabled for the TRACE level.

Parameters:
message - the message string
params - the parameter values that are to replace the variables in the format string

trace

public void trace(Throwable t,
                  String message,
                  Object... params)
Log an exception (throwable) at the TRACE level with an accompanying message. If the exception is null, then this method calls trace(String, Object...).

Parameters:
t - the exception (throwable) to log
message - the message accompanying the exception
params - the parameter values that are to replace the variables in the format string

warn

public void warn(I18n message,
                 Object... params)
Log a message at the WARNING level according to the specified format and (optional) parameters. The message should contain a pair of empty curly braces for each of the parameter, which should be passed in the correct order. This method is efficient and avoids superfluous object creation when the logger is disabled for the WARNING level.

Parameters:
message - the message string
params - the parameter values that are to replace the variables in the format string

warn

public void warn(Throwable t,
                 I18n message,
                 Object... params)
Log an exception (throwable) at the WARNING level with an accompanying message. If the exception is null, then this method calls warn(I18n, Object...).

Parameters:
t - the exception (throwable) to log
message - the message accompanying the exception
params - the parameter values that are to replace the variables in the format string

isDebugEnabled

public boolean isDebugEnabled()
Return whether messages at the DEBUG level are being logged.

Returns:
true if DEBUG log messages are currently being logged, or false otherwise.

isTraceEnabled

public boolean isTraceEnabled()
Return whether messages at the TRACE level are being logged.

Returns:
true if TRACE log messages are currently being logged, or false otherwise.

getLevel

public Logger.Level getLevel()
Get the logging level at which this logger is current set.

Returns:
the current logging level


Copyright © 2008-2010 JBoss, a division of Red Hat. All Rights Reserved.