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 |
|---|---|
void |
error(String format,
Object... args)
Logs a formattable message that uses
{} as the placeholder at error 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. |
void |
verbose(String format,
Object... args)
Logs a formattable message that uses
{} as the placeholder at verbose 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.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 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 format, Object... args)
{} as the placeholder at warning log level.
Code samples
Logging a message at warning log level.
Throwableexception = newIllegalArgumentException("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 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.runtimeException - RuntimeException to be logged and returned.RuntimeException.NullPointerException - If runtimeException is null.public RuntimeException logExceptionAsError(RuntimeException runtimeException)
RuntimeException at the error level and returns it to be thrown.runtimeException - RuntimeException to be logged and returned.RuntimeException.NullPointerException - If runtimeException is null.Copyright © 2019 Microsoft Corporation. All rights reserved.