Class SimpleULogger

java.lang.Object
org.apache.log4j.spi.SimpleULogger
All Implemented Interfaces:
ULogger

public final class SimpleULogger extends Object implements ULogger
A simple implementation that logs messages of level INFO or higher on the console (System.out).

The output includes the relative time in milliseconds, thread name, level, logger name, and the message followed by the line separator for the host. In log4j terms it amounts to the "%r [%t] %level %logger - %m%n" pattern.

 176 [main] INFO examples.Sort - Populating an array of 2 elements in reverse.
 225 [main] INFO examples.SortAlgo - Entered the sort method.
 304 [main] INFO SortAlgo.DUMP - Dump of interger array:
 317 [main] INFO SortAlgo.DUMP - Element [0] = 0
 331 [main] INFO SortAlgo.DUMP - Element [1] = 1
 343 [main] INFO examples.Sort - The next log statement should be an error msg.
 346 [main] ERROR SortAlgo.DUMP - Tried to dump an uninitialized array.
 at org.log4j.examples.SortAlgo.dump(SortAlgo.java:58)
 at org.log4j.examples.Sort.main(Sort.java:64)
 467 [main] INFO  examples.Sort - Exiting main method.
 
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    ERROR string literal.
    private static final String
    INFO string literal.
    static final String
    Line separator.
    private final String
    Logger name.
    private static long
    Mark the time when this class gets loaded into memory.
    private static final String
    WARN string literal.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Constructor is private to force construction through getLogger.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Log a message object with the DEBUG level.
    void
    debug(Object parameterizedMsg, Object param1)
    Log a parameterized message object at the DEBUG level.
    void
    Log a message object with the DEBUG level including the stack trace of the Throwablet passed as parameter.
    void
    debug(String parameterizedMsg, Object param1, Object param2)
    Log a parameterized message object at the DEBUG level.
    void
    Log a message object with the ERROR level.
    void
    error(Object parameterizedMsg, Object param1)
    Log a parameterized message object at the ERROR level.
    void
    Log a message object with the ERROR level including the stack trace of the Throwablet passed as parameter.
    void
    error(String parameterizedMsg, Object param1, Object param2)
    Log a parameterized message object at the ERROR level.
    Creates a new instance.
    void
    info(Object msg)
    Log a message object with the INFO level.
    void
    info(Object parameterizedMsg, Object param1)
    Log a parameterized message object at the INFO level.
    void
    Log a message object with the INFO level including the stack trace of the Throwablet passed as parameter.
    void
    info(String parameterizedMsg, Object param1, Object param2)
    Log a parameterized message object at the INFO level.
    boolean
    Is the logger instance enabled for the DEBUG level?
    boolean
    Is the logger instance enabled for the ERROR level?
    boolean
    Is the logger instance enabled for the INFO level?
    boolean
    Is the logger instance enabled for the WARN level?
    private void
    log(String level, String message, Throwable t)
    This is our internal implementation for logging regular (non-parameterized) log messages.
    private void
    parameterizedLog(String level, Object parameterizedMsg, Object param1, Object param2)
    For parameterized messages, first substitute parameters and then log.
    void
    warn(Object msg)
    Log a message object with the WARN level.
    void
    warn(Object parameterizedMsg, Object param1)
    Log a parameterized message object at the WARN level.
    void
    Log a message object with the WARN level including the stack trace of the Throwablet passed as parameter.
    void
    warn(String parameterizedMsg, Object param1, Object param2)
    Log a parameterized message object at the WARN level.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • loggerName

      private final String loggerName
      Logger name.
    • startTime

      private static long startTime
      Mark the time when this class gets loaded into memory.
    • LINE_SEPARATOR

      public static final String LINE_SEPARATOR
      Line separator.
    • INFO_STR

      private static final String INFO_STR
      INFO string literal.
      See Also:
    • WARN_STR

      private static final String WARN_STR
      WARN string literal.
      See Also:
    • ERROR_STR

      private static final String ERROR_STR
      ERROR string literal.
      See Also:
  • Constructor Details

    • SimpleULogger

      private SimpleULogger(String name)
      Constructor is private to force construction through getLogger.
      Parameters:
      name - logger name
  • Method Details

    • getLogger

      public static SimpleULogger getLogger(String name)
      Creates a new instance.
      Parameters:
      name - logger name
      Returns:
      logger.
    • isDebugEnabled

      public boolean isDebugEnabled()
      Is the logger instance enabled for the DEBUG level?
      Specified by:
      isDebugEnabled in interface ULogger
      Returns:
      true if debug is enabled.
    • debug

      public void debug(Object msg)
      Log a message object with the DEBUG level.
      Specified by:
      debug in interface ULogger
      Parameters:
      msg - - the message object to be logged
    • debug

      public void debug(Object parameterizedMsg, Object param1)
      Log a parameterized message object at the DEBUG level.

      This form is useful in avoiding the superflous object creation problem when invoking this method while it is disabled.

      Specified by:
      debug in interface ULogger
      Parameters:
      parameterizedMsg - - the parameterized message object
      param1 - - the parameter
    • debug

      public void debug(String parameterizedMsg, Object param1, Object param2)
      Log a parameterized message object at the DEBUG level.

      This form is useful in avoiding the superflous object creation problem when invoking this method while it is disabled.

      Specified by:
      debug in interface ULogger
      Parameters:
      parameterizedMsg - - the parameterized message object
      param1 - - the first parameter
      param2 - - the second parameter
    • debug

      public void debug(Object msg, Throwable t)
      Log a message object with the DEBUG level including the stack trace of the Throwablet passed as parameter.
      Specified by:
      debug in interface ULogger
      Parameters:
      msg - the message object to log.
      t - the exception to log, including its stack trace.
    • log

      private void log(String level, String message, Throwable t)
      This is our internal implementation for logging regular (non-parameterized) log messages.
      Parameters:
      level - level
      message - message
      t - throwable
    • parameterizedLog

      private void parameterizedLog(String level, Object parameterizedMsg, Object param1, Object param2)
      For parameterized messages, first substitute parameters and then log.
      Parameters:
      level - level
      parameterizedMsg - message pattern
      param1 - param1
      param2 - param2
    • isInfoEnabled

      public boolean isInfoEnabled()
      Is the logger instance enabled for the INFO level?
      Specified by:
      isInfoEnabled in interface ULogger
      Returns:
      true if debug is enabled.
    • info

      public void info(Object msg)
      Log a message object with the INFO level.
      Specified by:
      info in interface ULogger
      Parameters:
      msg - - the message object to be logged
    • info

      public void info(Object parameterizedMsg, Object param1)
      Log a parameterized message object at the INFO level.

      This form is useful in avoiding the superflous object creation problem when invoking this method while it is disabled.

      Specified by:
      info in interface ULogger
      Parameters:
      parameterizedMsg - - the parameterized message object
      param1 - - the parameter
    • info

      public void info(String parameterizedMsg, Object param1, Object param2)
      Log a parameterized message object at the INFO level.

      This form is useful in avoiding the superflous object creation problem when invoking this method while it is disabled.

      Specified by:
      info in interface ULogger
      Parameters:
      parameterizedMsg - - the parameterized message object
      param1 - - the first parameter
      param2 - - the second parameter
    • info

      public void info(Object msg, Throwable t)
      Log a message object with the INFO level including the stack trace of the Throwablet passed as parameter.
      Specified by:
      info in interface ULogger
      Parameters:
      msg - the message object to log.
      t - the exception to log, including its stack trace.
    • isWarnEnabled

      public boolean isWarnEnabled()
      Is the logger instance enabled for the WARN level?
      Specified by:
      isWarnEnabled in interface ULogger
      Returns:
      true if debug is enabled.
    • warn

      public void warn(Object msg)
      Log a message object with the WARN level.
      Specified by:
      warn in interface ULogger
      Parameters:
      msg - - the message object to be logged
    • warn

      public void warn(Object parameterizedMsg, Object param1)
      Log a parameterized message object at the WARN level.

      This form is useful in avoiding the superflous object creation problem when invoking this method while it is disabled.

      Specified by:
      warn in interface ULogger
      Parameters:
      parameterizedMsg - - the parameterized message object
      param1 - - the parameter
    • warn

      public void warn(String parameterizedMsg, Object param1, Object param2)
      Log a parameterized message object at the WARN level.

      This form is useful in avoiding the superflous object creation problem when invoking this method while it is disabled.

      Specified by:
      warn in interface ULogger
      Parameters:
      parameterizedMsg - - the parameterized message object
      param1 - - the first parameter
      param2 - - the second parameter
    • warn

      public void warn(Object msg, Throwable t)
      Log a message object with the WARN level including the stack trace of the Throwablet passed as parameter.
      Specified by:
      warn in interface ULogger
      Parameters:
      msg - the message object to log.
      t - the exception to log, including its stack trace.
    • isErrorEnabled

      public boolean isErrorEnabled()
      Is the logger instance enabled for the ERROR level?
      Specified by:
      isErrorEnabled in interface ULogger
      Returns:
      true if debug is enabled.
    • error

      public void error(Object msg)
      Log a message object with the ERROR level.
      Specified by:
      error in interface ULogger
      Parameters:
      msg - - the message object to be logged
    • error

      public void error(Object parameterizedMsg, Object param1)
      Log a parameterized message object at the ERROR level.

      This form is useful in avoiding the superflous object creation problem when invoking this method while it is disabled.

      Specified by:
      error in interface ULogger
      Parameters:
      parameterizedMsg - - the parameterized message object
      param1 - - the parameter
    • error

      public void error(String parameterizedMsg, Object param1, Object param2)
      Log a parameterized message object at the ERROR level.

      This form is useful in avoiding the superflous object creation problem when invoking this method while it is disabled.

      Specified by:
      error in interface ULogger
      Parameters:
      parameterizedMsg - - the parameterized message object
      param1 - - the first parameter
      param2 - - the second parameter
    • error

      public void error(Object msg, Throwable t)
      Log a message object with the ERROR level including the stack trace of the Throwablet passed as parameter.
      Specified by:
      error in interface ULogger
      Parameters:
      msg - the message object to log.
      t - the exception to log, including its stack trace.