Class Log4jContextFactory
java.lang.Object
org.apache.logging.log4j.core.impl.Log4jContextFactory
- All Implemented Interfaces:
ShutdownCallbackRegistry,LoggerContextFactory
public class Log4jContextFactory
extends Object
implements LoggerContextFactory, ShutdownCallbackRegistry
Factory to locate a ContextSelector and then load a LoggerContext.
-
Field Summary
Fields inherited from interface org.apache.logging.log4j.core.util.ShutdownCallbackRegistry
SHUTDOWN_CALLBACK_REGISTRY, SHUTDOWN_HOOK_MARKER -
Constructor Summary
ConstructorsConstructorDescriptionInitializes the ContextSelector from system propertyConstants.LOG4J_CONTEXT_SELECTOR.Log4jContextFactory(ContextSelector selector) Initializes this factory's ContextSelector with the specified selector.Log4jContextFactory(ContextSelector selector, ShutdownCallbackRegistry shutdownCallbackRegistry) Constructs a Log4jContextFactory using the provided ContextSelector and ShutdownRegistrationStrategy.Log4jContextFactory(ShutdownCallbackRegistry shutdownCallbackRegistry) Constructs a Log4jContextFactory using the ContextSelector fromConstants.LOG4J_CONTEXT_SELECTORand the provided ShutdownRegistrationStrategy. -
Method Summary
Modifier and TypeMethodDescriptionaddShutdownCallback(Runnable callback) Adds a Runnable shutdown callback to this class.getContext(String fqcn, ClassLoader loader, Object externalContext, boolean currentContext) Loads the LoggerContext using the ContextSelector.getContext(String fqcn, ClassLoader loader, Object externalContext, boolean currentContext, URI configLocation, String name) Loads the LoggerContext using the ContextSelector.getContext(String fqcn, ClassLoader loader, Object externalContext, boolean currentContext, List<URI> configLocations, String name) getContext(String fqcn, ClassLoader loader, Object externalContext, boolean currentContext, Configuration configuration) Loads the LoggerContext using the ContextSelector using the provided ConfigurationgetContext(String fqcn, ClassLoader loader, Object externalContext, boolean currentContext, ConfigurationSource source) Loads the LoggerContext using the ContextSelector.getContext(String fqcn, ClassLoader loader, Map.Entry<String, Object> entry, boolean currentContext, URI configLocation, String name) Returns the ContextSelector.Returns the ShutdownCallbackRegistrybooleanhasContext(String fqcn, ClassLoader loader, boolean currentContext) Checks to see if a LoggerContext is installed.booleanbooleanvoidremoveContext(LoggerContext context) Removes knowledge of a LoggerContext.voidshutdown(String fqcn, ClassLoader loader, boolean currentContext, boolean allContexts)
-
Constructor Details
-
Log4jContextFactory
public Log4jContextFactory()Initializes the ContextSelector from system propertyConstants.LOG4J_CONTEXT_SELECTOR. -
Log4jContextFactory
Initializes this factory's ContextSelector with the specified selector.- Parameters:
selector- the selector to use
-
Log4jContextFactory
Constructs a Log4jContextFactory using the ContextSelector fromConstants.LOG4J_CONTEXT_SELECTORand the provided ShutdownRegistrationStrategy.- Parameters:
shutdownCallbackRegistry- the ShutdownRegistrationStrategy to use- Since:
- 2.1
-
Log4jContextFactory
public Log4jContextFactory(ContextSelector selector, ShutdownCallbackRegistry shutdownCallbackRegistry) Constructs a Log4jContextFactory using the provided ContextSelector and ShutdownRegistrationStrategy.- Parameters:
selector- the selector to useshutdownCallbackRegistry- the ShutdownRegistrationStrategy to use- Since:
- 2.1
-
-
Method Details
-
getContext
public LoggerContext getContext(String fqcn, ClassLoader loader, Object externalContext, boolean currentContext) Loads the LoggerContext using the ContextSelector.- Specified by:
getContextin interfaceLoggerContextFactory- Parameters:
fqcn- The fully qualified class name of the caller.loader- The ClassLoader to use or null.currentContext- If true returns the current Context, if false returns the Context appropriate for the caller if a more appropriate Context can be determined.externalContext- An external context (such as a ServletContext) to be associated with the LoggerContext.- Returns:
- The LoggerContext.
-
getContext
public LoggerContext getContext(String fqcn, ClassLoader loader, Object externalContext, boolean currentContext, ConfigurationSource source) Loads the LoggerContext using the ContextSelector.- Parameters:
fqcn- The fully qualified class name of the caller.loader- The ClassLoader to use or null.externalContext- An external context (such as a ServletContext) to be associated with the LoggerContext.currentContext- If true returns the current Context, if false returns the Context appropriate for the caller if a more appropriate Context can be determined.source- The configuration source.- Returns:
- The LoggerContext.
-
getContext
public LoggerContext getContext(String fqcn, ClassLoader loader, Object externalContext, boolean currentContext, Configuration configuration) Loads the LoggerContext using the ContextSelector using the provided Configuration- Parameters:
fqcn- The fully qualified class name of the caller.loader- The ClassLoader to use or null.externalContext- An external context (such as a ServletContext) to be associated with the LoggerContext.currentContext- If true returns the current Context, if false returns the Context appropriate for the caller if a more appropriate Context can be determined.configuration- The Configuration.- Returns:
- The LoggerContext.
-
getContext
public LoggerContext getContext(String fqcn, ClassLoader loader, Object externalContext, boolean currentContext, URI configLocation, String name) Loads the LoggerContext using the ContextSelector.- Specified by:
getContextin interfaceLoggerContextFactory- Parameters:
fqcn- The fully qualified class name of the caller.loader- The ClassLoader to use or null.externalContext- An external context (such as a ServletContext) to be associated with the LoggerContext.currentContext- If true returns the current Context, if false returns the Context appropriate for the caller if a more appropriate Context can be determined.configLocation- The location of the configuration for the LoggerContext (or null).- Returns:
- The LoggerContext.
-
getContext
public LoggerContext getContext(String fqcn, ClassLoader loader, Map.Entry<String, Object> entry, boolean currentContext, URI configLocation, String name) -
getContext
public LoggerContext getContext(String fqcn, ClassLoader loader, Object externalContext, boolean currentContext, List<URI> configLocations, String name) -
shutdown
- Specified by:
shutdownin interfaceLoggerContextFactory
-
hasContext
Checks to see if a LoggerContext is installed.- Specified by:
hasContextin interfaceLoggerContextFactory- Parameters:
fqcn- The fully qualified class name of the caller.loader- The ClassLoader to use or null.currentContext- If true returns the current Context, if false returns the Context appropriate for the caller if a more appropriate Context can be determined.- Returns:
- true if a LoggerContext has been installed, false otherwise.
- Since:
- 3.0
-
getSelector
Returns the ContextSelector.- Returns:
- The ContextSelector.
-
getShutdownCallbackRegistry
Returns the ShutdownCallbackRegistry- Returns:
- the ShutdownCallbackRegistry
- Since:
- 2.4
-
removeContext
Removes knowledge of a LoggerContext.- Specified by:
removeContextin interfaceLoggerContextFactory- Parameters:
context- The context to remove.
-
isClassLoaderDependent
public boolean isClassLoaderDependent()- Specified by:
isClassLoaderDependentin interfaceLoggerContextFactory
-
addShutdownCallback
Description copied from interface:ShutdownCallbackRegistryAdds a Runnable shutdown callback to this class. Note: The returnedCancellablemust be retained on heap by caller to avoid premature garbage-collection of the registered callback (and to ensure the callback runs on shutdown).- Specified by:
addShutdownCallbackin interfaceShutdownCallbackRegistry- Parameters:
callback- the shutdown callback to be executed upon shutdown.- Returns:
- a Cancellable wrapper of the provided callback or
nullif the shutdown hook is disabled and cannot be added.
-
isShutdownHookEnabled
public boolean isShutdownHookEnabled()
-