Wrapper around java-util Logger that simplifies its usage. In
addition it provides a similar api like slf4j. It is not meant to act as
logging-facade like slf4j or jakarta-commons-logging. It only provides a
little syntactic sugar for the built-in logger.
Obtaining a logger
private static final CuiLogger log = new CuiLogger(SomeClass.class);
private static final CuiLogger log = new CuiLogger("SomeLoggerName");
private static final CuiLogger log = CuiLoggerFactory.getLogger();
Logging
CuiLogger provides an implicit code guard, if used correctly. Used
correctly hereby means to either use formatting with parameter or
incorporating Supplier for generating the actual log-message. For
other means of creating a message you still can use code guards.
log.trace("Parameter-type matches exactly '%s'", assignableSource);
log.debug("Adding found method '%s' on class '%s'", name, clazz);
log.info("Starting up application");
// In order not to mess up with the ellipsis parameter
// exceptions must be the first parameter
log.warn(e, "Exception during lenientFormat for '%s'", objectToString);
log.error(e, "Caught an exception");
log.info(() -> "Supplier can be used as well");
log.error(e, () -> "Even with exceptions");
log.trace(() -> "I will only be evaluated if the trace-level for is enabled");
Formatting
Like slf4j there is a simple way of formatting log-messages. In addition to
'{}' the formatting supports '%s' as well. At runtime it replaces the '{}'
tokens with '%s' and passes the data to
MoreStrings.lenientFormat(String, Object...) for creating the actual
log-message. As a variant providing a Supplier works as well.
- Author:
- Oliver Wolff
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidLog a message at the debug level.voidLog a message at the debug level.voidLog a message at the debug level.voidLog a message at the debug level.voidLog a message at the debug level.voidLog a message at the debug level.voidLog a message at the error level.voidLog a message at the error level.voidLog a message at the error level.voidLog a message at the error level.voidLog a message at the error level.voidLog a message at the error level.getName()voidLog a message at the info level.voidLog a message at the info level.voidLog a message at the info level.voidLog a message at the info level.voidLog a message at the info level.voidLog a message at the info level.booleanIs the logger instance enabled for the debug level?booleanIs the logger instance enabled for the error level?booleanIs the logger instance enabled for the info level?booleanIs the logger instance enabled for the trace level?booleanIs the logger instance enabled for the warn level?voidLog a message at the trace level.voidLog a message at the trace level.voidLog a message at the trace level.voidLog a message at the trace level.voidLog a message at the trace level.voidLog a message at the trace level.voidLog a message at the warn level.voidLog a message at the warn level.voidLog a message at the warn level.voidLog a message at the warn level.voidLog a message at the warn level.voidLog a message at the warn level.
-
Constructor Details
-
Method Details
-
isTraceEnabled
Is the logger instance enabled for the trace level?- Returns:
trueif this CuiLogger is enabled for the trace level, false otherwise.
-
trace
Log a message at the trace level.- Parameters:
msg- the message string to be logged
-
trace
Log a message at the trace level.- Parameters:
msg- the message string to be logged
-
trace
Log a message at the trace level.- Parameters:
throwable- to be loggedmsg- the message string to be logged
-
trace
Log a message at the trace level.- Parameters:
msg- the message string to be loggedthrowable- to be logged
-
trace
Log a message at the trace level.- Parameters:
throwable- to be loggedtemplate- to be used for formatting, see class-documentation for details on formattingparameter- to be used for replacing the placeholder
-
trace
Log a message at the trace level.- Parameters:
template- to be used for formatting, see class-documentation for details on formattingparameter- to be used for replacing the placeholder
-
isDebugEnabled
Is the logger instance enabled for the debug level?- Returns:
trueif this CuiLogger is enabled for the debug level, false otherwise.
-
debug
Log a message at the debug level.- Parameters:
msg- the message string to be logged
-
debug
Log a message at the debug level.- Parameters:
msg- the message string to be loggedthrowable- to be logged
-
debug
Log a message at the debug level.- Parameters:
msg- the message string to be logged
-
debug
Log a message at the debug level.- Parameters:
throwable- to be loggedmsg- the message string to be logged
-
debug
Log a message at the debug level.- Parameters:
throwable- to be loggedtemplate- to be used for formatting, see class-documentation for details on formattingparameter- to be used for replacing the placeholder
-
debug
Log a message at the debug level.- Parameters:
template- to be used for formatting, see class-documentation for details on formattingparameter- to be used for replacing the placeholder
-
isInfoEnabled
Is the logger instance enabled for the info level?- Returns:
trueif this CuiLogger is enabled for the info level, false otherwise.
-
info
Log a message at the info level.- Parameters:
msg- the message string to be logged
-
info
Log a message at the info level.- Parameters:
msg- the message string to be loggedthrowable- to be logged
-
info
Log a message at the info level.- Parameters:
msg- the message string to be logged
-
info
Log a message at the info level.- Parameters:
throwable- to be loggedmsg- the message string to be logged
-
info
Log a message at the info level.- Parameters:
throwable- to be loggedtemplate- to be used for formatting, see class-documentation for details on formattingparameter- to be used for replacing the placeholder
-
info
Log a message at the info level.- Parameters:
template- to be used for formatting, see class-documentation for details on formattingparameter- to be used for replacing the placeholder
-
isWarnEnabled
Is the logger instance enabled for the warn level?- Returns:
trueif this CuiLogger is enabled for the warn level, false otherwise.
-
warn
Log a message at the warn level.- Parameters:
msg- the message string to be logged
-
warn
Log a message at the warn level.- Parameters:
msg- the message string to be loggedthrowable- to be logged
-
warn
Log a message at the warn level.- Parameters:
msg- the message string to be logged
-
warn
Log a message at the warn level.- Parameters:
throwable- to be loggedmsg- the message string to be logged
-
warn
Log a message at the warn level.- Parameters:
throwable- to be loggedtemplate- to be used for formatting, see class-documentation for details on formattingparameter- to be used for replacing the placeholder
-
warn
Log a message at the warn level.- Parameters:
template- to be used for formatting, see class-documentation for details on formattingparameter- to be used for replacing the placeholder
-
isErrorEnabled
Is the logger instance enabled for the error level?- Returns:
trueif this CuiLogger is enabled for the error level, false otherwise.
-
error
Log a message at the error level.- Parameters:
msg- the message string to be logged
-
error
Log a message at the error level.- Parameters:
msg- the message string to be loggedthrowable- to be logged
-
error
Log a message at the error level.- Parameters:
msg- the message string to be logged
-
error
Log a message at the error level.- Parameters:
throwable- to be loggedmsg- the message string to be logged
-
error
Log a message at the error level.- Parameters:
throwable- to be loggedtemplate- to be used for formatting, see class-documentation for details on formattingparameter- to be used for replacing the placeholder
-
error
Log a message at the error level.- Parameters:
template- to be used for formatting, see class-documentation for details on formattingparameter- to be used for replacing the placeholder
-
getName
- Returns:
- the name / class of the underlying logger
-
getLogLevel
- Returns:
- CUI log level derived from JUL log level. E.g. FINEST(300) matches TRACE(400), CONFIG(700) matches DEBUG(500), ALL matches TRACE.
-