net.protempore.utils
Class LoggerUtils

java.lang.Object
  extended by net.protempore.utils.LoggerUtils

public final class LoggerUtils
extends java.lang.Object

A simple logging utility class that assists with logging messages by only created a formatted message string if the given log level is enabled and there is at least 1 message argument, and only invoking the actual log method if the given level is enabled.

This allows you to not have to guard all of your log statements in order to prevent the performance hit of string concatenation when logging is disabled for a given level. Instead of needing to do:

if (logger.isDebugEnabled()) { logger.debug("The baz with id '" + id + "' and name '" + name, "' is foo bar."); }

You can do the much easier on the eyes: debug(logger, "The baz with id '%s' and name '%s' is foo bar.", id, name);


Method Summary
static void debug(org.apache.commons.logging.Log logger, java.lang.String msg, java.lang.Object... msgArgs)
           Log a debug message.
static void error(org.apache.commons.logging.Log logger, java.lang.String msg, java.lang.Object... msgArgs)
           Log an error message.
static void error(org.apache.commons.logging.Log logger, java.lang.Throwable t, java.lang.String msg, java.lang.Object... msgArgs)
           Log an error message and a Throwable.
static void fatal(org.apache.commons.logging.Log logger, java.lang.String msg, java.lang.Object... msgArgs)
           Log a fatal error message.
static void fatal(org.apache.commons.logging.Log logger, java.lang.Throwable t, java.lang.String msg, java.lang.Object... msgArgs)
           Log a fatal error message and a Throwable.
static void info(org.apache.commons.logging.Log logger, java.lang.String msg, java.lang.Object... msgArgs)
           Log an info message.
static void trace(org.apache.commons.logging.Log logger, java.lang.String msg, java.lang.Object... msgArgs)
           Log a trace message.
static void warn(org.apache.commons.logging.Log logger, java.lang.String msg, java.lang.Object... msgArgs)
           Log a warn message.
static void warn(org.apache.commons.logging.Log logger, java.lang.Throwable t, java.lang.String msg, java.lang.Object... msgArgs)
           Log a warn message and a Throwable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

trace

public static void trace(org.apache.commons.logging.Log logger,
                         java.lang.String msg,
                         java.lang.Object... msgArgs)

Log a trace message.

If the given logger has the trace level enabled, then log the given msg at that level, using String.format to interpolate the msgArgs into the msg string if there is at least 1 msgArg.

Parameters:
logger - A non-null logger.
msg - A non-null string.
msgArgs - Zero or more msg args.

debug

public static void debug(org.apache.commons.logging.Log logger,
                         java.lang.String msg,
                         java.lang.Object... msgArgs)

Log a debug message.

If the given logger has the debug level enabled, then log the given msg at that level, using String.format to interpolate the msgArgs into the msg string if there is at least 1 msgArg.

Parameters:
logger - A non-null logger.
msg - A non-null string.
msgArgs - Zero or more msg args.

info

public static void info(org.apache.commons.logging.Log logger,
                        java.lang.String msg,
                        java.lang.Object... msgArgs)

Log an info message.

If the given logger has the info level enabled, then log the given msg at that level, using String.format to interpolate the msgArgs into the msg string if there is at least 1 msgArg.

Parameters:
logger - A non-null logger.
msg - A non-null string.
msgArgs - Zero or more msg args.

warn

public static void warn(org.apache.commons.logging.Log logger,
                        java.lang.String msg,
                        java.lang.Object... msgArgs)

Log a warn message.

If the given logger has the warn level enabled, then log the given msg at that level, using String.format to interpolate the msgArgs into the msg string if there is at least 1 msgArg.

Parameters:
logger - A non-null logger.
msg - A non-null string.
msgArgs - Zero or more msg args.

warn

public static void warn(org.apache.commons.logging.Log logger,
                        java.lang.Throwable t,
                        java.lang.String msg,
                        java.lang.Object... msgArgs)

Log a warn message and a Throwable.

If the given logger has the warn level enabled, then log the given msg at that level, using String.format to interpolate the msgArgs into the msg string if there is at least 1 msgArg, and logging the given Throwable arg as well.

Parameters:
logger - A non-null logger.
t - A throwable to be logged.
msg - A non-null string.
msgArgs - Zero or more msg args.

error

public static void error(org.apache.commons.logging.Log logger,
                         java.lang.String msg,
                         java.lang.Object... msgArgs)

Log an error message.

If the given logger has the error level enabled, then log the given msg at that level, using String.format to interpolate the msgArgs into the msg string if there is at least 1 msgArg.

Parameters:
logger - A non-null logger.
msg - A non-null string.
msgArgs - Zero or more msg args.

error

public static void error(org.apache.commons.logging.Log logger,
                         java.lang.Throwable t,
                         java.lang.String msg,
                         java.lang.Object... msgArgs)

Log an error message and a Throwable.

If the given logger has the error level enabled, then log the given msg at that level, using String.format to interpolate the msgArgs into the msg string if there is at least 1 msgArg, and logging the given Throwable arg as well.

Parameters:
logger - A non-null logger.
t - A throwable to be logged.
msg - A non-null string.
msgArgs - Zero or more msg args.

fatal

public static void fatal(org.apache.commons.logging.Log logger,
                         java.lang.String msg,
                         java.lang.Object... msgArgs)

Log a fatal error message.

If the given logger has the fatal level enabled, then log the given msg at that level, using String.format to interpolate the msgArgs into the msg string if there is at least 1 msgArg.

Parameters:
logger - A non-null logger.
msg - A non-null string.
msgArgs - Zero or more msg args.

fatal

public static void fatal(org.apache.commons.logging.Log logger,
                         java.lang.Throwable t,
                         java.lang.String msg,
                         java.lang.Object... msgArgs)

Log a fatal error message and a Throwable.

If the given logger has the fatal level enabled, then log the given msg at that level, using String.format to interpolate the msgArgs into the msg string if there is at least 1 msgArg, and logging the given Throwable arg as well.

Parameters:
logger - A non-null logger.
t - A throwable to be logged.
msg - A non-null string.
msgArgs - Zero or more msg args.