Class Logger

java.lang.Object
net.simplace.core.logging.Logger

public class Logger extends Object
Static facade for logging with log4j. It holds the log level of the application (default INFO) so that callers can check it cheaply before building messages.

Use like:

if (Logger.isERROR()) Logger.ERROR("message", aException, this);
Additional features:
Author:
Andreas Enders
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Log levels in ascending severity.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    DEBUG(String aStringToLog, Object aThisInstance)
    Logs a message at level DEBUG, if enabled.
    static void
    DEBUG(String aStringToLog, Throwable aExceptionToLog, Object aThisInstance)
    Logs a message with exception at level DEBUG, if enabled.
    static void
    ERROR(String aStringToLog, Throwable aException, Object This)
    Logs a message with exception at level ERROR, if enabled.
    static void
    FATAL(String aStringToLog, Throwable aExceptionToLog, Object aThisInstance)
    Logs a message with exception at level FATAL (always logged).
    static void
    INFO(String aStringToLog, Object aThisInstance)
    Logs a message at level INFO, if enabled.
    static void
    INFO(String aStringToLog, Throwable aExceptionToLog, Object aThisInstance)
    Logs a message with exception at level INFO, if enabled.
    static boolean
     
    static boolean
     
    static boolean
     
    static boolean
     
    static boolean
     
    static void
    setDisableStackTrace(boolean aDisableStackTrace)
    Sets if stack traces are suppressed.
    static void
    setLogLevel(int aLogLevel)
    Use a numeric index to set a log level.
    static void
    Sets the log level: this level and all more severe levels are logged.
    static void
    setUseLOGGERclazz(boolean aUseLOGGERclazz)
    Sets if the log4j logger of the caller's class is used; for performance reasons you can always log to the root logger instead.
    static void
    WARN(String aStringToLog, Object aThisInstance)
    Logs a message at level WARN, if enabled.
    static void
    WARN(String aStringToLog, Throwable aExceptionToLog, Object aThisInstance)
    Logs a message with exception at level WARN, if enabled.

    Methods inherited from class Object

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

    • Logger

      public Logger()
  • Method Details

    • setLogLevel

      public static void setLogLevel(Logger.LOGLEVEL aLogLevel)
      Sets the log level: this level and all more severe levels are logged. FATAL is always logged.
      Parameters:
      aLogLevel - the lowest level to log
    • setLogLevel

      public static void setLogLevel(int aLogLevel)
      Use a numeric index to set a log level. Used for external calls from e.g. R.

      Use LOGLEVEL.values() to see what log levels the indices correspond to.

      Parameters:
      aLogLevel - index in Logger.LOGLEVEL (0 = TRACE ... 5 = FATAL)
    • setUseLOGGERclazz

      public static void setUseLOGGERclazz(boolean aUseLOGGERclazz)
      Sets if the log4j logger of the caller's class is used; for performance reasons you can always log to the root logger instead.
      Parameters:
      aUseLOGGERclazz - true (default) for the logger of the caller's class, false for the root logger
    • setDisableStackTrace

      public static void setDisableStackTrace(boolean aDisableStackTrace)
      Sets if stack traces are suppressed.
      Parameters:
      aDisableStackTrace - true to log messages without stack traces (default false)
    • isTRACE

      public static boolean isTRACE()
      Returns:
      true if TRACE is logged
    • isDEBUG

      public static boolean isDEBUG()
      Returns:
      true if DEBUG is logged
    • isINFO

      public static boolean isINFO()
      Returns:
      true if INFO is logged
    • isWARN

      public static boolean isWARN()
      Returns:
      true if WARN is logged
    • isERROR

      public static boolean isERROR()
      Returns:
      true if ERROR is logged
    • DEBUG

      public static void DEBUG(String aStringToLog, Throwable aExceptionToLog, Object aThisInstance)
      Logs a message with exception at level DEBUG, if enabled.
      Parameters:
      aStringToLog - the message
      aExceptionToLog - the exception, logged with stack trace unless stack traces are disabled
      aThisInstance - the calling object or class; selects the log4j logger by class name
    • DEBUG

      public static void DEBUG(String aStringToLog, Object aThisInstance)
      Logs a message at level DEBUG, if enabled.
      Parameters:
      aStringToLog - the message
      aThisInstance - the calling object or class; selects the log4j logger by class name
    • INFO

      public static void INFO(String aStringToLog, Throwable aExceptionToLog, Object aThisInstance)
      Logs a message with exception at level INFO, if enabled.
      Parameters:
      aStringToLog - the message
      aExceptionToLog - the exception, logged with stack trace unless stack traces are disabled
      aThisInstance - the calling object or class; selects the log4j logger by class name
    • INFO

      public static void INFO(String aStringToLog, Object aThisInstance)
      Logs a message at level INFO, if enabled.
      Parameters:
      aStringToLog - the message
      aThisInstance - the calling object or class; selects the log4j logger by class name
    • WARN

      public static void WARN(String aStringToLog, Throwable aExceptionToLog, Object aThisInstance)
      Logs a message with exception at level WARN, if enabled.
      Parameters:
      aStringToLog - the message
      aExceptionToLog - the exception, logged with stack trace unless stack traces are disabled
      aThisInstance - the calling object or class; selects the log4j logger by class name
    • WARN

      public static void WARN(String aStringToLog, Object aThisInstance)
      Logs a message at level WARN, if enabled.
      Parameters:
      aStringToLog - the message
      aThisInstance - the calling object or class; selects the log4j logger by class name
    • ERROR

      public static void ERROR(String aStringToLog, Throwable aException, Object This)
      Logs a message with exception at level ERROR, if enabled.
      Parameters:
      aStringToLog - the message
      aException - the exception, logged with stack trace unless stack traces are disabled
      This - the calling object or class; selects the log4j logger by class name
    • FATAL

      public static void FATAL(String aStringToLog, Throwable aExceptionToLog, Object aThisInstance)
      Logs a message with exception at level FATAL (always logged).
      Parameters:
      aStringToLog - the message
      aExceptionToLog - the exception, logged with stack trace unless stack traces are disabled
      aThisInstance - the calling object or class; selects the log4j logger by class name