public abstract class LoggerConfigurator
extends java.lang.Object
LoggerConfigurator
makes it possible to separate the configuration of any and all Logger
s from the use of them.
By default a LoggerConfigurator
that applies the following set of operations to any and all Logger
s are provided:
logger.getMessageChannel().addMessageChannelObserver((messageChannel, message) -> System.out.printf("%s%n", message));
logger.start();
Modifier | Constructor and Description |
---|---|
protected |
LoggerConfigurator()
Constructs a new
LoggerConfigurator instance. |
Modifier and Type | Method and Description |
---|---|
static Logger |
configure(Logger logger)
Call this method when you want to configure a given
Logger instance. |
abstract Logger |
doConfigure(Logger logger)
Called by the
configure(Logger) method of this class, when it's time to configure a given Logger instance. |
static void |
setLoggerConfigurator(LoggerConfigurator loggerConfigurator)
Sets a new
LoggerConfigurator instance to configure any and all Logger s. |
protected LoggerConfigurator()
LoggerConfigurator
instance.public abstract Logger doConfigure(Logger logger)
configure(Logger)
method of this class, when it's time to configure a given Logger
instance.
Returns logger
itself.
If logger
is null
, a NullPointerException
may be thrown. But no guarantees can be made for all LoggerConfigurator
instances.
The default LoggerConfigurator
does, however, throw a NullPointerException
.
logger
- the Logger
to configureLogger
itselfjava.lang.NullPointerException
- thrown if, and only if, logger
is null
public static Logger configure(Logger logger)
Logger
instance.
Returns logger
itself.
Some of the methods provided by the Logger
class itself will call this method as part of creation.
If logger
is null
, a NullPointerException
may be thrown. But no guarantees can be made for all LoggerConfigurator
instances.
The default LoggerConfigurator
does, however, throw a NullPointerException
. Aside from that, it also starts the Logger
if it was not already started.
logger
- the Logger
to configureLogger
itselfjava.lang.NullPointerException
- thrown if, and only if, logger
is null
public static void setLoggerConfigurator(LoggerConfigurator loggerConfigurator)
LoggerConfigurator
instance to configure any and all Logger
s.
This method is useful if you want to swap the default behavior of logging to standard out. Maybe you want to log with Apache Log4J instead, but still use this library and its APIs.
If loggerConfigurator
is null
, a NullPointerException
will be thrown.
loggerConfigurator
- the new LoggerConfigurator
java.lang.NullPointerException
- thrown if, and only if, loggerConfigurator
is null