Class ClientLogger
- java.lang.Object
-
- com.azure.android.core.logging.ClientLogger
-
public class ClientLogger extends java.lang.Object
This is a fluent logger helper class that wraps a pluggableLogger
.This logger logs formattable messages that use
{}
as the placeholder. When athrowable
is the last argument of the format varargs and the logger is enabled forverbose
, the stack trace for the throwable is logged.Log level hierarchy
-
-
Constructor Summary
Constructors Constructor Description ClientLogger(java.lang.Class<?> clazz)
Retrieves a logger for the passed class using theLoggerFactory
.ClientLogger(java.lang.String className)
Retrieves a logger for the passed class name using theLoggerFactory
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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 aterror
log level.void
error(java.lang.String format, java.lang.Object... args)
Logs a formattable message that uses{}
as the placeholder aterror
log level.void
info(java.lang.String message)
Logs a message atinfo
log level.void
info(java.lang.String format, java.lang.Object... args)
Logs a formattable message that uses{}
as the placeholder atinformational
log level.java.lang.RuntimeException
logExceptionAsError(java.lang.RuntimeException runtimeException)
Logs theRuntimeException
at the error level and returns it to be thrown.java.lang.RuntimeException
logExceptionAsWarning(java.lang.RuntimeException runtimeException)
Logs theRuntimeException
at the warning level and returns it to be thrown.<T extends java.lang.Throwable>
TlogThrowableAsError(T throwable)
Logs theThrowable
at the error level and returns it to be thrown.<T extends java.lang.Throwable>
TlogThrowableAsWarning(T throwable)
Logs theThrowable
at the warning level and returns it to be thrown.void
verbose(java.lang.String message)
Logs a message atverbose
log level.void
verbose(java.lang.String format, java.lang.Object... args)
Logs a formattable message that uses{}
as the placeholder atverbose
log level.void
warning(java.lang.String message)
Logs a message atwarning
log level.void
warning(java.lang.String format, java.lang.Object... args)
Logs a formattable message that uses{}
as the placeholder atwarning
log level.
-
-
-
Constructor Detail
-
ClientLogger
public ClientLogger(java.lang.Class<?> clazz)
Retrieves a logger for the passed class using theLoggerFactory
.- Parameters:
clazz
- Class creating the logger.
-
ClientLogger
public ClientLogger(java.lang.String className)
Retrieves a logger for the passed class name using theLoggerFactory
.- Parameters:
className
- Class name creating the logger.- Throws:
java.lang.RuntimeException
- it is an error.
-
-
Method Detail
-
verbose
public void verbose(java.lang.String message)
Logs a message atverbose
log level.- Parameters:
message
- The message to log.
-
verbose
public void verbose(java.lang.String format, java.lang.Object... args)
Logs a formattable message that uses{}
as the placeholder atverbose
log level.- Parameters:
format
- The formattable message to log.args
- Arguments for the message. If an exception is being logged, the last argument should be theThrowable
.
-
info
public void info(java.lang.String message)
Logs a message atinfo
log level.- Parameters:
message
- The message to log.
-
info
public void info(java.lang.String format, java.lang.Object... args)
Logs a formattable message that uses{}
as the placeholder atinformational
log level.- Parameters:
format
- The formattable message to logargs
- Arguments for the message. If an exception is being logged, the last argument should be theThrowable
.
-
warning
public void warning(java.lang.String message)
Logs a message atwarning
log level.- Parameters:
message
- The message to log.
-
warning
public void warning(java.lang.String format, java.lang.Object... args)
Logs a formattable message that uses{}
as the placeholder atwarning
log level.- Parameters:
format
- The formattable message to log.args
- Arguments for the message. If an exception is being logged, the last argument should be theThrowable
.
-
error
public void error(java.lang.String message)
Logs a message aterror
log level.- Parameters:
message
- The message to log.
-
error
public void error(java.lang.String format, java.lang.Object... args)
Logs a formattable message that uses{}
as the placeholder aterror
log level.- Parameters:
format
- The formattable message to log.args
- Arguments for the message. If an exception is being logged, the last argument should be theThrowable
.
-
logExceptionAsWarning
public java.lang.RuntimeException logExceptionAsWarning(java.lang.RuntimeException runtimeException)
Logs theRuntimeException
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 uselogThrowableAsWarning(Throwable)
instead.- Parameters:
runtimeException
- RuntimeException to be logged and returned.- Returns:
- The passed
RuntimeException
. - Throws:
java.lang.NullPointerException
- IfruntimeException
isnull
.
-
logThrowableAsWarning
public <T extends java.lang.Throwable> T logThrowableAsWarning(T throwable)
Logs theThrowable
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 uselogExceptionAsWarning(RuntimeException)
instead.- Type Parameters:
T
- Type of the Throwable being logged.- Parameters:
throwable
- Throwable to be logged and returned.- Returns:
- The passed
Throwable
. - Throws:
java.lang.NullPointerException
- Ifthrowable
isnull
.
-
logExceptionAsError
public java.lang.RuntimeException logExceptionAsError(java.lang.RuntimeException runtimeException)
Logs theRuntimeException
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 uselogThrowableAsError(Throwable)
instead.- Parameters:
runtimeException
- RuntimeException to be logged and returned.- Returns:
- The passed
RuntimeException
. - Throws:
java.lang.NullPointerException
- IfruntimeException
isnull
.
-
logThrowableAsError
public <T extends java.lang.Throwable> T logThrowableAsError(T throwable)
Logs theThrowable
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 uselogExceptionAsError(RuntimeException)
instead.- Type Parameters:
T
- Type of the Throwable being logged.- Parameters:
throwable
- Throwable to be logged and returned.- Returns:
- The passed
Throwable
. - Throws:
java.lang.NullPointerException
- Ifthrowable
isnull
.
-
canLogAtLevel
public boolean canLogAtLevel(LogLevel logLevel)
Determines if the app or environment logger support logging at the given log level.- Parameters:
logLevel
- Logging level for the log message.- Returns:
- Flag indicating if the environment and logger are configured to support logging at the given log level.
-
-