public class ClientLogger
extends java.lang.Object
Logger
.
This logger logs formattable messages that use {}
as the placeholder. When a throwable
is the last argument of the format varargs and the logger is enabled for
verbose
, the stack trace for the throwable is logged.
Log level hierarchy
Constructor and Description |
---|
ClientLogger(java.lang.Class<?> clazz)
Retrieves a logger for the passed class using the
LoggerFactory . |
ClientLogger(java.lang.String className)
Retrieves a logger for the passed class name using the
LoggerFactory . |
Modifier and Type | Method and Description |
---|---|
boolean |
canLogAtLevel(LogLevel logLevel)
Determines if the app or environment logger support logging at the given log level.
|
void |
error(java.lang.String message)
Logs a message at
error log level. |
void |
error(java.lang.String format,
java.lang.Object... args)
Logs a formattable message that uses
{} as the placeholder at error log level. |
void |
info(java.lang.String message)
Logs a message at
info log level. |
void |
info(java.lang.String format,
java.lang.Object... args)
Logs a formattable message that uses
{} as the placeholder at informational log level. |
java.lang.RuntimeException |
logExceptionAsError(java.lang.RuntimeException runtimeException)
Logs the
RuntimeException at the error level and returns it to be thrown. |
java.lang.RuntimeException |
logExceptionAsWarning(java.lang.RuntimeException runtimeException)
Logs the
RuntimeException at the warning level and returns it to be thrown. |
<T extends java.lang.Throwable> |
logThrowableAsError(T throwable)
Logs the
Throwable at the error level and returns it to be thrown. |
<T extends java.lang.Throwable> |
logThrowableAsWarning(T throwable)
Logs the
Throwable at the warning level and returns it to be thrown. |
void |
verbose(java.lang.String message)
Logs a message at
verbose log level. |
void |
verbose(java.lang.String format,
java.lang.Object... args)
Logs a formattable message that uses
{} as the placeholder at verbose log level. |
void |
warning(java.lang.String message)
Logs a message at
warning log level. |
void |
warning(java.lang.String format,
java.lang.Object... args)
Logs a formattable message that uses
{} as the placeholder at warning log level. |
public ClientLogger(java.lang.Class<?> clazz)
LoggerFactory
.clazz
- Class creating the logger.public ClientLogger(java.lang.String className)
LoggerFactory
.className
- Class name creating the logger.java.lang.RuntimeException
- it is an error.public void verbose(java.lang.String message)
verbose
log level.message
- The message to log.public void verbose(java.lang.String format, java.lang.Object... args)
{}
as the placeholder at verbose
log level.format
- The formattable message to log.args
- Arguments for the message. If an exception is being logged, the last argument should be the
Throwable
.public void info(java.lang.String message)
info
log level.message
- The message to log.public void info(java.lang.String format, java.lang.Object... args)
{}
as the placeholder at informational
log level.format
- The formattable message to logargs
- Arguments for the message. If an exception is being logged, the last argument should be the
Throwable
.public void warning(java.lang.String message)
warning
log level.message
- The message to log.public void warning(java.lang.String format, java.lang.Object... args)
{}
as the placeholder at warning
log level.format
- The formattable message to log.args
- Arguments for the message. If an exception is being logged, the last argument should be the
Throwable
.public void error(java.lang.String message)
error
log level.message
- The message to log.public void error(java.lang.String format, java.lang.Object... args)
{}
as the placeholder at error
log level.format
- The formattable message to log.args
- Arguments for the message. If an exception is being logged, the last argument should be the
Throwable
.public java.lang.RuntimeException logExceptionAsWarning(java.lang.RuntimeException runtimeException)
RuntimeException
at the warning level and returns it to be thrown.
This API covers the cases where a runtime exception type needs to be thrown and logged. If a Throwable
is
being logged use logThrowableAsWarning(Throwable)
instead.
runtimeException
- RuntimeException to be logged and returned.RuntimeException
.java.lang.NullPointerException
- If runtimeException
is null
.public <T extends java.lang.Throwable> T logThrowableAsWarning(T throwable)
Throwable
at the warning level and returns it to be thrown.
This API covers the cases where a checked exception type needs to be thrown and logged. If a RuntimeException
is being logged use logExceptionAsWarning(RuntimeException)
instead.
T
- Type of the Throwable being logged.throwable
- Throwable to be logged and returned.Throwable
.java.lang.NullPointerException
- If throwable
is null
.public java.lang.RuntimeException logExceptionAsError(java.lang.RuntimeException runtimeException)
RuntimeException
at the error level and returns it to be thrown.
This API covers the cases where a runtime exception type needs to be thrown and logged. If a Throwable
is
being logged use logThrowableAsError(Throwable)
instead.
runtimeException
- RuntimeException to be logged and returned.RuntimeException
.java.lang.NullPointerException
- If runtimeException
is null
.public <T extends java.lang.Throwable> T logThrowableAsError(T throwable)
Throwable
at the error level and returns it to be thrown.
This API covers the cases where a checked exception type needs to be thrown and logged. If a RuntimeException
is being logged use logExceptionAsError(RuntimeException)
instead.
T
- Type of the Throwable being logged.throwable
- Throwable to be logged and returned.Throwable
.java.lang.NullPointerException
- If throwable
is null
.public boolean canLogAtLevel(LogLevel logLevel)
logLevel
- Logging level for the log message.