L- The specific
BasicContextualLoggerimplementation to be used by the manager, as determined by the managed logging domain.
public class ContextualLoggingManager<L extends BasicContextualLogger> extends java.lang.Object
This is the central component of the contextual logging framework.
Instances of the manager are accessed by providing a valid LogDomain
getInstance(LogDomain). There will be 1 single manager instance
per LogDomain and each instance will be lazily created, on demand, and
will be stored in the ADFContext's scope defined in the LogDomain.
The main purpose of this manager is to keep track of the contextual
loggers created for each LogDomain. New loggers must be created via method
openLogger(LoggerProvider) and will be immediately stacked in the
manager, obeying the LIFO storage method. Therefore, the lastly created
logger will always be the current, which may be accessed via
A call to
closeCurrentLogger() will trigger a call to
on the current logger and will also cause it to be removed from the top of the
logger stack maintained by the manager, thus promoting its precursor to current,
It is important and expected that consumers will be responsible for
matching every call to method openLogger with a corresponding call to
This component should allow consumers to easily define the logger to be used by multiple methods and/or classes throughout the flow delimited by latest matching calls to openLogger and closeCurrentLogger.
Bellow is an example of the recommended use pattern:
public class MyClass
public static final LogDomain<ContextualLogger> domain = new LogDomain<ContextualLogger>("My Domain", "foo.bar");}
public void method1()
LoggerProvider<ContextualLogger> provider = new LoggerProvider<ContextualLogger>(domain, "foo.bar.log1");}
CurrentLoggingManager<ContextualLogger> mgr = CurrentLoggingManager.getInstance(domain);
public class Util
public void method2()}
CurrentLoggingManager<ContextualLogger> mgr = CurrentLoggingManager.getInstance(MyClass.domain);}
ContextualLogger logger = mgr.getCurrentLogger(); logger.info("I'm logging using the current contextual logger");
|Modifier and Type||Method and Description|
Close all managed loggers that might still be open.
Close the current logger, if any, remove it from the internal logger stack and promote the precursor logger to current, if any.
Get the current logger, resulting from the last call to
Get the logging domain managed by this manager.
Get the right manager instance for the given domain.
This method will use the given provider to create a new logger of the given type L and immediately set it as current.
Will return the key used to store the manager in the ADFContext's scope defined by its managed logging domain.
public final L openLogger(LoggerProvider<L> provider)
provider- The logger provider which will be used to create the new logger
java.lang.IllegalArgumentException- If the given provider does not belong to the managed logging domain
public final void closeCurrentLogger()
public final L getCurrentLogger()
public final void closeAllLoggers()
As a best practice, we recommend calling this method in a finally block in the code that controls the life cycle where this manager is inserted. This will make sure that any pending end/close messages will be properly published in the right sequence.
In the most common use case, when the manager instance will be stored
in ADFContext's request scope, this method will be called automatically
by the framework whenever the scope gets invalidated. This will actually be true
for any other container-managed scope implementing
public java.lang.String toString()
public static <L extends BasicContextualLogger> ContextualLoggingManager<L> getInstance(LogDomain<L> domain)
L- The type of ContextualLogger associated with the domain
domain- The logging domain to be managed. When null, this method will also return null.