Class CuiLogger
- java.lang.Object
-
- io.cui.tools.logging.CuiLogger
-
public class CuiLogger extends Object
Wrapper around java-util
Loggerthat 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
CuiLoggerprovides an implicit code guard, if used correctly. Used correctly hereby means to either use formatting with parameter or incorporatingSupplierfor 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 parameterlog.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 aSupplierworks as well.- Author:
- Oliver Wolff
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voiddebug(String msg)Log a message at the debug level.voiddebug(String template, Object... parameter)Log a message at the debug level.voiddebug(String msg, Throwable throwable)Log a message at the debug level.voiddebug(Throwable throwable, String template, Object... parameter)Log a message at the debug level.voiddebug(Throwable throwable, Supplier<String> msg)Log a message at the debug level.voiddebug(Supplier<String> msg)Log a message at the debug level.voiderror(String msg)Log a message at the error level.voiderror(String template, Object... parameter)Log a message at the error level.voiderror(String msg, Throwable throwable)Log a message at the error level.voiderror(Throwable throwable, String template, Object... parameter)Log a message at the error level.voiderror(Throwable throwable, Supplier<String> msg)Log a message at the error level.voiderror(Supplier<String> msg)Log a message at the error level.LogLevelgetLogLevel()StringgetName()voidinfo(String msg)Log a message at the info level.voidinfo(String template, Object... parameter)Log a message at the info level.voidinfo(String msg, Throwable throwable)Log a message at the info level.voidinfo(Throwable throwable, String template, Object... parameter)Log a message at the info level.voidinfo(Throwable throwable, Supplier<String> msg)Log a message at the info level.voidinfo(Supplier<String> msg)Log a message at the info level.booleanisDebugEnabled()Is the logger instance enabled for the debug level?booleanisErrorEnabled()Is the logger instance enabled for the error level?booleanisInfoEnabled()Is the logger instance enabled for the info level?booleanisTraceEnabled()Is the logger instance enabled for the trace level?booleanisWarnEnabled()Is the logger instance enabled for the warn level?voidtrace(String msg)Log a message at the trace level.voidtrace(String template, Object... parameter)Log a message at the trace level.voidtrace(String msg, Throwable throwable)Log a message at the trace level.voidtrace(Throwable throwable, String template, Object... parameter)Log a message at the trace level.voidtrace(Throwable throwable, Supplier<String> msg)Log a message at the trace level.voidtrace(Supplier<String> msg)Log a message at the trace level.voidwarn(String msg)Log a message at the warn level.voidwarn(String template, Object... parameter)Log a message at the warn level.voidwarn(String msg, Throwable throwable)Log a message at the warn level.voidwarn(Throwable throwable, String template, Object... parameter)Log a message at the warn level.voidwarn(Throwable throwable, Supplier<String> msg)Log a message at the warn level.voidwarn(Supplier<String> msg)Log a message at the warn level.
-
-
-
Method Detail
-
isTraceEnabled
public boolean isTraceEnabled()
Is the logger instance enabled for the trace level?- Returns:
trueif this CuiLogger is enabled for the trace level, false otherwise.
-
trace
public void trace(String msg)
Log a message at the trace level.- Parameters:
msg- the message string to be logged
-
trace
public void trace(Supplier<String> msg)
Log a message at the trace level.- Parameters:
msg- the message string to be logged
-
trace
public void trace(Throwable throwable, Supplier<String> msg)
Log a message at the trace level.- Parameters:
throwable- to be loggedmsg- the message string to be logged
-
trace
public void trace(String msg, Throwable throwable)
Log a message at the trace level.- Parameters:
msg- the message string to be loggedthrowable- to be logged
-
trace
public void trace(Throwable throwable, String template, Object... parameter)
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
public void trace(String template, Object... parameter)
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
public boolean isDebugEnabled()
Is the logger instance enabled for the debug level?- Returns:
trueif this CuiLogger is enabled for the debug level, false otherwise.
-
debug
public void debug(String msg)
Log a message at the debug level.- Parameters:
msg- the message string to be logged
-
debug
public void debug(String msg, Throwable throwable)
Log a message at the debug level.- Parameters:
msg- the message string to be loggedthrowable- to be logged
-
debug
public void debug(Supplier<String> msg)
Log a message at the debug level.- Parameters:
msg- the message string to be logged
-
debug
public void debug(Throwable throwable, Supplier<String> msg)
Log a message at the debug level.- Parameters:
throwable- to be loggedmsg- the message string to be logged
-
debug
public void debug(Throwable throwable, String template, Object... parameter)
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
public void debug(String template, Object... parameter)
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
public boolean isInfoEnabled()
Is the logger instance enabled for the info level?- Returns:
trueif this CuiLogger is enabled for the info level, false otherwise.
-
info
public void info(String msg)
Log a message at the info level.- Parameters:
msg- the message string to be logged
-
info
public void info(String msg, Throwable throwable)
Log a message at the info level.- Parameters:
msg- the message string to be loggedthrowable- to be logged
-
info
public void info(Supplier<String> msg)
Log a message at the info level.- Parameters:
msg- the message string to be logged
-
info
public void info(Throwable throwable, Supplier<String> msg)
Log a message at the info level.- Parameters:
throwable- to be loggedmsg- the message string to be logged
-
info
public void info(Throwable throwable, String template, Object... parameter)
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
public void info(String template, Object... parameter)
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
public boolean isWarnEnabled()
Is the logger instance enabled for the warn level?- Returns:
trueif this CuiLogger is enabled for the warn level, false otherwise.
-
warn
public void warn(String msg)
Log a message at the warn level.- Parameters:
msg- the message string to be logged
-
warn
public void warn(String msg, Throwable throwable)
Log a message at the warn level.- Parameters:
msg- the message string to be loggedthrowable- to be logged
-
warn
public void warn(Supplier<String> msg)
Log a message at the warn level.- Parameters:
msg- the message string to be logged
-
warn
public void warn(Throwable throwable, Supplier<String> msg)
Log a message at the warn level.- Parameters:
throwable- to be loggedmsg- the message string to be logged
-
warn
public void warn(Throwable throwable, String template, Object... parameter)
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
public void warn(String template, Object... parameter)
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
public boolean isErrorEnabled()
Is the logger instance enabled for the error level?- Returns:
trueif this CuiLogger is enabled for the error level, false otherwise.
-
error
public void error(String msg)
Log a message at the error level.- Parameters:
msg- the message string to be logged
-
error
public void error(String msg, Throwable throwable)
Log a message at the error level.- Parameters:
msg- the message string to be loggedthrowable- to be logged
-
error
public void error(Supplier<String> msg)
Log a message at the error level.- Parameters:
msg- the message string to be logged
-
error
public void error(Throwable throwable, Supplier<String> msg)
Log a message at the error level.- Parameters:
throwable- to be loggedmsg- the message string to be logged
-
error
public void error(Throwable throwable, String template, Object... parameter)
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
public void error(String template, Object... parameter)
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
-
getLogLevel
public LogLevel 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.
-
-