public abstract class Logger extends Object
Further more, it provides governance over the logging codes used across the system using the LogInfo
annotation. While the log code being capable of pointing to the absolute positions in the code it could also be
used for log monitoring solutions. The log code emitted by the logger has 9
characters, of the
following form. Note that the code is always padded with preceding '0' and the padding process is transparent from
the user API.
Let the code be of the form TMMMLLSCCC
the following table describes the full code
T | Component Type | Single digit one of 10 predefined types ComponentType |
MMM | Module Id | 3 digit module id specified in the annotation LogInfo |
LL | Logger Id | 2 digit logger id specified in the annotation LogInfo |
S | Severity/Log Level | log level of the log statement, one of [T, D, I, W, E] characters to denote log level |
CCC | Code | 3 digit code used to identify individual log lines |
Any instance creation of this logger should be done via the LoggerFactory
. The logger factory has a set
of static methods providing Logger instances for user API. The usage of this logger should be as follows;
@LogInfo(componentType = ComponentType.ENGINE, moduleId = 123, loggerId = 45, codes = {1,2})
public class MyClass {
private static final Logger logger = LoggerFactory.getLogger(MyClass.class);
public static void main(String[] args) {
logger.info(1, "Starting the processing");
String result = null;
int status;
// snippet of code
logger.debug(2, "Completed with result code {}", result);
}
}
Note that the logger could also add context information using a CloseableContext
for the thread context
or generally known as MDC
LoggerFactory
,
LogInfo
,
ComponentType
Modifier and Type | Field and Description |
---|---|
static String |
CODE_KEY
The thread context key used to include the logger code argument
|
static ThreadLocal<CloseableLogContext> |
LOG_CONTEXT |
Constructor and Description |
---|
Logger() |
Logger(int componentType,
int module,
int loggerId)
Constructs a logger with the given logger name, type, status and the severity
|
Modifier and Type | Method and Description |
---|---|
void |
debug(int status,
String format,
Object... arguments) |
void |
debug(int status,
String format,
Supplier<?>... argumentSuppliers) |
protected abstract void |
debugImpl(String format,
Object... arguments) |
void |
error(int status,
String format,
Object... arguments) |
void |
error(int status,
String format,
Supplier<?>... argumentSuppliers) |
protected abstract void |
errorImpl(String format,
Object... arguments) |
void |
errorOnDebugOrWarn(int status,
String format,
Throwable t,
Object... arguments) |
protected abstract CloseableContext |
getContext() |
abstract Optional<String> |
getName()
Gives the name of the logger
|
void |
info(int status,
String format,
Object... arguments) |
void |
info(int status,
String format,
Supplier<?>... argumentSuppliers) |
protected abstract void |
infoImpl(String format,
Object... arguments) |
abstract boolean |
isDebugEnabled()
Whether debug is enabled for this logger, or in other words the logger's log level is set to
Level.DEBUG or lower. |
abstract boolean |
isErrorEnabled()
Whether error is enabled for this logger, or in other words the logger's log level is set to
Level.ERROR or lower. |
abstract boolean |
isInfoEnabled()
Whether info is enabled for this logger, or in other words the logger's log level is set to
Level.INFO or lower. |
abstract boolean |
isTraceEnabled()
Whether trace is enabled for this logger, or in other words the logger's log level is set to
Level.TRACE |
abstract boolean |
isWarnEnabled()
Whether warn is enabled for this logger, or in other words the logger's log level is set to
Level.WARN or lower. |
void |
trace(int status,
String format,
Object... arguments) |
void |
trace(int status,
String format,
Supplier<?>... argumentSuppliers) |
protected abstract void |
traceImpl(String format,
Object... arguments) |
void |
warn(int status,
String format,
Object... arguments) |
void |
warn(int status,
String format,
Supplier<?>... argumentSuppliers) |
protected abstract void |
warnImpl(String format,
Object... arguments) |
public static final String CODE_KEY
public static final ThreadLocal<CloseableLogContext> LOG_CONTEXT
public Logger(int componentType, int module, int loggerId)
componentType
- component type argument to derive codePrefixmodule
- module identifier argument to derive codePrefixloggerId
- logger identifier argument to derive codePrefixLogger()
public abstract Optional<String> getName()
public abstract boolean isTraceEnabled()
Level.TRACE
public abstract boolean isDebugEnabled()
Level.DEBUG
or lower.public abstract boolean isInfoEnabled()
Level.INFO
or lower.public abstract boolean isWarnEnabled()
Level.WARN
or lower.public abstract boolean isErrorEnabled()
Level.ERROR
or lower.public final void errorOnDebugOrWarn(int status, String format, Throwable t, Object... arguments)
protected abstract CloseableContext getContext()
Copyright © 2016–2019 AdroitLogic. All rights reserved.