Class Logger
java.lang.Object
net.simplace.core.logging.Logger
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:
- for performance reasons you can always log to the root logger (the class name is then prepended to the
message):
setUseLOGGERclazz(boolean)withfalse - stack traces can be suppressed with
setDisableStackTrace(boolean)
- Author:
- Andreas Enders
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidLogs a message at level DEBUG, if enabled.static voidLogs a message with exception at level DEBUG, if enabled.static voidLogs a message with exception at level ERROR, if enabled.static voidLogs a message with exception at level FATAL (always logged).static voidLogs a message at level INFO, if enabled.static voidLogs a message with exception at level INFO, if enabled.static booleanisDEBUG()static booleanisERROR()static booleanisINFO()static booleanisTRACE()static booleanisWARN()static voidsetDisableStackTrace(boolean aDisableStackTrace) Sets if stack traces are suppressed.static voidsetLogLevel(int aLogLevel) Use a numeric index to set a log level.static voidsetLogLevel(Logger.LOGLEVEL aLogLevel) Sets the log level: this level and all more severe levels are logged.static voidsetUseLOGGERclazz(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 voidLogs a message at level WARN, if enabled.static voidLogs a message with exception at level WARN, if enabled.
-
Constructor Details
-
Logger
public Logger()
-
-
Method Details
-
setLogLevel
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 inLogger.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,falsefor the root logger
-
setDisableStackTrace
public static void setDisableStackTrace(boolean aDisableStackTrace) Sets if stack traces are suppressed.- Parameters:
aDisableStackTrace-trueto log messages without stack traces (defaultfalse)
-
isTRACE
public static boolean isTRACE()- Returns:
trueif TRACE is logged
-
isDEBUG
public static boolean isDEBUG()- Returns:
trueif DEBUG is logged
-
isINFO
public static boolean isINFO()- Returns:
trueif INFO is logged
-
isWARN
public static boolean isWARN()- Returns:
trueif WARN is logged
-
isERROR
public static boolean isERROR()- Returns:
trueif ERROR is logged
-
DEBUG
Logs a message with exception at level DEBUG, if enabled.- Parameters:
aStringToLog- the messageaExceptionToLog- the exception, logged with stack trace unless stack traces are disabledaThisInstance- the calling object or class; selects the log4j logger by class name
-
DEBUG
-
INFO
Logs a message with exception at level INFO, if enabled.- Parameters:
aStringToLog- the messageaExceptionToLog- the exception, logged with stack trace unless stack traces are disabledaThisInstance- the calling object or class; selects the log4j logger by class name
-
INFO
-
WARN
Logs a message with exception at level WARN, if enabled.- Parameters:
aStringToLog- the messageaExceptionToLog- the exception, logged with stack trace unless stack traces are disabledaThisInstance- the calling object or class; selects the log4j logger by class name
-
WARN
-
ERROR
Logs a message with exception at level ERROR, if enabled.- Parameters:
aStringToLog- the messageaException- the exception, logged with stack trace unless stack traces are disabledThis- the calling object or class; selects the log4j logger by class name
-
FATAL
Logs a message with exception at level FATAL (always logged).- Parameters:
aStringToLog- the messageaExceptionToLog- the exception, logged with stack trace unless stack traces are disabledaThisInstance- the calling object or class; selects the log4j logger by class name
-