Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle ADF Model
11g Release 1 (11.1.1.9.0)

E52932-01


oracle.adfinternal.model.logging.contextual
Class ContextualLoggingManager<L extends BasicContextualLogger>

java.lang.Object
  extended by oracle.adfinternal.model.logging.contextual.ContextualLoggingManager<L>

Type Parameters:
L - The specific BasicContextualLogger implementation 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 to 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 getCurrentLogger(). A call to closeCurrentLogger() will trigger a call to BasicContextualLogger.close() 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, if any.

It is important and expected that consumers will be responsible for matching every call to method openLogger with a corresponding call to closeCurrentLogger().

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);
try
{
Util.method2();
}
finally
{
mgr.closeCurrentLogger();
}
}

}

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");
}

}

Since:
11.1.1.7.2
See Also:
LogDomain, LoggerProvider

Method Summary
 void closeAllLoggers()
          Close all managed loggers that might still be open.
 void closeCurrentLogger()
          Close the current logger, if any, remove it from the internal logger stack and promote the precursor logger to current, if any.
 L getCurrentLogger()
          Get the current logger, resulting from the last call to openLogger(oracle.adfinternal.model.logging.contextual.LoggerProvider<L>).
 LogDomain<L> getDomain()
          Get the logging domain managed by this manager.
static
<L extends BasicContextualLogger>
ContextualLoggingManager<L>
getInstance(LogDomain<L> domain)
          Get the right manager instance for the given domain.
 L openLogger(LoggerProvider<L> provider)
          This method will use the given provider to create a new logger of the given type L and immediately set it as current.
 java.lang.String toString()
          Will return the key used to store the manager in the ADFContext's scope defined by its managed logging domain.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Method Detail

getDomain

public final LogDomain<L> getDomain()
Get the logging domain managed by this manager.
Returns:
The managed domain

openLogger

public final L openLogger(LoggerProvider<L> provider)
This method will use the given provider to create a new logger of the given type L and immediately set it as current.
Parameters:
provider - The logger provider which will be used to create the new logger
Returns:
The newly created logger
Throws:
java.lang.IllegalArgumentException - If the given provider does not belong to the managed logging domain

closeCurrentLogger

public final void closeCurrentLogger()
Close the current logger, if any, remove it from the internal logger stack and promote the precursor logger to current, if any.

getCurrentLogger

public final L getCurrentLogger()
Get the current logger, resulting from the last call to openLogger(oracle.adfinternal.model.logging.contextual.LoggerProvider<L>).
Returns:
The current logger. Null will be returned if the internal logger stack is empty, unless the managed logging domain defines a default logger provider, in which case, this method will automatically call method openLogger passing the domain's default logger provider as argument.

closeAllLoggers

public final void closeAllLoggers()
Close all managed loggers that might still be open.

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 ADFScope.


toString

public java.lang.String toString()
Will return the key used to store the manager in the ADFContext's scope defined by its managed logging domain.
Overrides:
toString in class java.lang.Object
Returns:

getInstance

public static <L extends BasicContextualLogger> ContextualLoggingManager<L> getInstance(LogDomain<L> domain)
Get the right manager instance for the given domain. The manager instance will exist in the ADFContext's scope defined by the domain.
Type Parameters:
L - The type of ContextualLogger associated with the domain
Parameters:
domain - The logging domain to be managed. When null, this method will also return null.
Returns:
The manager instance associated with the domain or null if argument domain is also null

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle ADF Model
11g Release 1 (11.1.1.9.0)

E52932-01


Copyright © 1997, 2015, Oracle. All rights reserved.