public class ClientLogger extends Object
Logger.
This logger logs format-able messages that use {} as the placeholder. When a throwable is the last
argument of the format varargs and the logger is enabled for verbose logging the
stack trace for the throwable will be included in the log message.
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 |
|---|---|
ClientLogger |
asError()
Sets the logger to the error logging level.
|
ClientLogger |
asInfo()
Sets the logger to the info logging level.
|
ClientLogger |
asVerbose()
Sets the logger to the verbose logging level.
|
ClientLogger |
asWarning()
Sets the logger to the warning logging level.
|
void |
log(String format,
Object... args)
Logs a format-able message that uses
{} as the placeholder. |
public ClientLogger(Class clazz)
LoggerFactory.clazz - Class creating the logger.public ClientLogger(String className)
LoggerFactory.className - Class name creating the logger.public ClientLogger asVerbose()
public ClientLogger asInfo()
public ClientLogger asWarning()
public ClientLogger asError()
public void log(String format, Object... args)
{} as the placeholder.
Code Samples
Logging a message with the default log level
ClientLogger logger = new ClientLogger(Example.class);
logger.log("A message");
Logging a format-able warning
ClientLogger logger = new ClientLogger(Example.class);
logger.asWarning().log("A format-able message. Hello, {}", name);
Logging an error with stack trace
ClientLogger logger = new ClientLogger(Example.class);
try {
upload(resource);
} catch (Throwable ex) {
logger.asError().log("Failed to upload {}", resource.name(), ex);
}
format - Format-able message.args - Arguments for the message, if an exception is being logged last argument is the throwable.Copyright © 2019 Microsoft Corporation. All rights reserved.