public class ClientLogger extends 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.
A minimum logging level threshold is determined by the
AZURE_LOG_LEVEL environment configuration. By default logging is
disabled.
Log level hierarchy
Configuration| Constructor and Description |
|---|
ClientLogger(Class<?> clazz)
Retrieves a logger for the passed class using the
LoggerFactory. |
ClientLogger(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(String message)
Logs a message at
error log level. |
void |
error(String format,
Object... args)
Logs a formattable message that uses
{} as the placeholder at error log level. |
void |
info(String message)
Logs a message at
info log level. |
void |
info(String format,
Object... args)
Logs a formattable message that uses
{} as the placeholder at informational log level. |
RuntimeException |
logExceptionAsError(RuntimeException runtimeException)
Logs the
RuntimeException at the error level and returns it to be thrown. |
RuntimeException |
logExceptionAsWarning(RuntimeException runtimeException)
Logs the
RuntimeException at the warning level and returns it to be thrown. |
<T extends Throwable> |
logThowableAsWarning(T throwable)
Deprecated.
Use
ClientLogger.logThrowableAsWarning(Throwable) instead. |
<T extends Throwable> |
logThrowableAsError(T throwable)
Logs the
Throwable at the error level and returns it to be thrown. |
<T extends Throwable> |
logThrowableAsWarning(T throwable)
Logs the
Throwable at the warning level and returns it to be thrown. |
void |
verbose(String message)
Logs a message at
verbose log level. |
void |
verbose(String format,
Object... args)
Logs a formattable message that uses
{} as the placeholder at verbose log level. |
void |
warning(String message)
Logs a message at
warning log level. |
void |
warning(String format,
Object... args)
Logs a formattable message that uses
{} as the placeholder at warning log level. |
public ClientLogger(Class<?> clazz)
LoggerFactory.clazz - Class creating the logger.public ClientLogger(String className)
LoggerFactory.className - Class name creating the logger.RuntimeException - it is an error.public void verbose(String message)
verbose log level.
Code samples
Logging a message at verbose log level.
logger.verbose("A log message");
message - The message to log.public void verbose(String format, Object... args)
{} as the placeholder at verbose log level.
Code samples
Logging a message at verbose log level.
logger.verbose("A formattable message. Hello, {}", name);
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(String message)
info log level.
Code samples
Logging a message at verbose log level.
logger.info("A log message");
message - The message to log.public void info(String format, Object... args)
{} as the placeholder at informational log level.
Code samples
Logging a message at informational log level.
logger.info("A formattable message. Hello, {}", name);
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(String message)
warning log level.
Code samples
Logging a message at verbose log level.
Throwable detailedException = new IllegalArgumentException("A exception with a detailed message");
logger.warning(detailedException.getMessage());
message - The message to log.public void warning(String format, Object... args)
{} as the placeholder at warning log level.
Code samples
Logging a message at warning log level.
Throwable exception = new IllegalArgumentException("An invalid argument was encountered.");
logger.warning("A formattable message. Hello, {}", name, exception);
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(String message)
error log level.
Code samples
Logging a message at verbose log level.
try {
upload(resource);
} catch (IOException ex) {
logger.error(ex.getMessage());
}
message - The message to log.public void error(String format, Object... args)
{} as the placeholder at error log level.
Code samples
Logging an error with stack trace.
try {
upload(resource);
} catch (IOException ex) {
logger.error("A formattable message. Hello, {}", name, ex);
}
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 RuntimeException logExceptionAsWarning(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 ClientLogger.logThrowableAsWarning(Throwable) instead.
runtimeException - RuntimeException to be logged and returned.RuntimeException.NullPointerException - If runtimeException is null.@Deprecated public <T extends Throwable> T logThowableAsWarning(T throwable)
ClientLogger.logThrowableAsWarning(Throwable) instead.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 ClientLogger.logExceptionAsWarning(RuntimeException) instead.
T - Type of the Throwable being logged.throwable - Throwable to be logged and returned.Throwable.NullPointerException - If throwable is null.public <T extends 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 ClientLogger.logExceptionAsWarning(RuntimeException) instead.
T - Type of the Throwable being logged.throwable - Throwable to be logged and returned.Throwable.NullPointerException - If throwable is null.public RuntimeException logExceptionAsError(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 ClientLogger.logThrowableAsError(Throwable) instead.
runtimeException - RuntimeException to be logged and returned.RuntimeException.NullPointerException - If runtimeException is null.public <T extends 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 ClientLogger.logExceptionAsError(RuntimeException) instead.
T - Type of the Throwable being logged.throwable - Throwable to be logged and returned.Throwable.NullPointerException - If throwable is null.public boolean canLogAtLevel(LogLevel logLevel)
logLevel - Logging level for the log message.Copyright © 2021 Microsoft Corporation. All rights reserved.