Class Log


  • public final class Log
    extends Object

    A wafer thin wrapper around System.err that uses var-args to make it much more efficient to call the logging methods in without having to surround every call site with calls to Log.isXXXEnabled(). All the methods on this class take a variable length list of arguments and, only if logging is enabled for the level and channel being logged to, will those arguments be toString()'d and appended together.

    • Method Detail

      • getInstance

        public static Log getInstance​(Class<?> clazz)
        Get a Log instance to perform logging within the Class specified. Returns an instance of this class which wraps an instance of the commons logging Log class.
        Parameters:
        clazz - the Class which is going to be doing the logging
        Returns:
        a Log instance with which to log
      • setGlobalLogLevel

        public static void setGlobalLogLevel​(Log.LogLevel logLevel)
        Set the log level.
        Parameters:
        logLevel - The log level enumeration
      • getGlobalLogLevel

        public static Log.LogLevel getGlobalLogLevel()
        Get the log level.
        Returns:
        The enumeration for setting log levels.
      • setGlobalPrintStream

        public static void setGlobalPrintStream​(PrintStream stream)
        Set the PrintStream for writing.
        Parameters:
        stream - PrintStream to write to.
      • isEnabled

        public static final boolean isEnabled​(Log.LogLevel level)
        Returns true if the specified log level is enabled otherwise false.
      • getTimestamp

        protected String getTimestamp()
        Creates a date string for insertion into the log. Given that logs are sometimes held statically and SimpleDateFormat is not thread safe, currently creates an instance each time :/
      • error

        public final void error​(Throwable throwable,
                                Object... messageParts)
        Logs a Throwable and optional message parts at level error.
        Parameters:
        throwable - an instance of Throwable that should be logged with stack trace
        messageParts - zero or more objects which should be combined, by calling toString() to form the log message.
      • warn

        public final void warn​(Throwable throwable,
                               Object... messageParts)
        Logs a Throwable and optional message parts at level warn.
        Parameters:
        throwable - an instance of Throwable that should be logged with stack trace
        messageParts - zero or more objects which should be combined, by calling toString() to form the log message.
      • info

        public final void info​(Throwable throwable,
                               Object... messageParts)
        Logs a Throwable and optional message parts at level info.
        Parameters:
        throwable - an instance of Throwable that should be logged with stack trace
        messageParts - zero or more objects which should be combined, by calling toString() to form the log message.
      • debug

        public final void debug​(Throwable throwable,
                                Object... messageParts)
        Logs a Throwable and optional message parts at level debug.
        Parameters:
        throwable - an instance of Throwable that should be logged with stack trace
        messageParts - zero or more objects which should be combined, by calling toString() to form the log message.
      • error

        public final void error​(Object... messageParts)
        Logs one or more message parts at level error.
        Parameters:
        messageParts - one or more objects which should be combined, by calling toString() to form the log message.
      • warn

        public final void warn​(Object... messageParts)
        Logs one or more message parts at level warn.
        Parameters:
        messageParts - one or more objects which should be combined, by calling toString() to form the log message.
      • info

        public final void info​(Object... messageParts)
        Logs one or more message parts at level info.
        Parameters:
        messageParts - one or more objects which should be combined, by calling toString() to form the log message.
      • debug

        public final void debug​(Object... messageParts)
        Logs one or more message parts at level debug.
        Parameters:
        messageParts - one or more objects which should be combined, by calling toString() to form the log message.