Package org.apache.logging.log4j.web
Interface Log4jWebSupport
public interface Log4jWebSupport
Specifies an interface for setting and clearing a thread-bound
LoggerContext
in a Java EE web application.
Also defines constants for context parameter and attribute names. In most cases you will never need to use this
directly because the Log4j filter handles this task automatically. However, in async operations you should wrap
code that executes in separate threads with setLoggerContext()
and clearLoggerContext()
.
You can obtain the instance of this for your web application by retrieving the ServletContext
attribute named org.apache.logging.log4j.core.web.Log4jWebSupport.INSTANCE
. If needed, you can also obtain
the LoggerContext
instance for your web application by retrieving the ServletContext
attribute named
org.apache.logging.log4j.spi.LoggerContext.INSTANCE
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The attribute key for theServletContext
attribute that theLoggerContext
is stored in.static final String
TheServletContext
parameter name for the flag that disables Log4j's auto-initialization in Servlet 3.0+ web applications.static final String
TheServletContext
parameter name for the flag that disables Log4j's auto-shutdown in Servlet 3.0+ web applications.static final String
TheServletContext
parameter name for the JNDI flag.static final String
TheServletContext
parameter name for the location of the configuration.static final String
TheServletContext
parameter name for the name of theLoggerContext
.static final String
The attribute key for theServletContext
attribute that the singleton support instance is stored in. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the logger context set up insetLoggerContext()
.void
Sets the logger context so that code executing afterwards can easily and quickly access loggers viaLogManager.getLogger()
.void
wrapExecution
(Runnable runnable) Sets the logger context by callingsetLoggerContext()
, executes the runnable argument, then clears the logger context by callingclearLoggerContext()
.
-
Field Details
-
LOG4J_CONTEXT_NAME
TheServletContext
parameter name for the name of theLoggerContext
.- See Also:
-
LOG4J_CONFIG_LOCATION
TheServletContext
parameter name for the location of the configuration.- See Also:
-
IS_LOG4J_CONTEXT_SELECTOR_NAMED
TheServletContext
parameter name for the JNDI flag.- See Also:
-
IS_LOG4J_AUTO_INITIALIZATION_DISABLED
TheServletContext
parameter name for the flag that disables Log4j's auto-initialization in Servlet 3.0+ web applications. Set a context parameter with this name to "true" to disable auto-initialization.- See Also:
-
IS_LOG4J_AUTO_SHUTDOWN_DISABLED
TheServletContext
parameter name for the flag that disables Log4j's auto-shutdown in Servlet 3.0+ web applications. Set a context parameter with this name to "true" to disable auto-shutdown.- See Also:
-
SUPPORT_ATTRIBUTE
The attribute key for theServletContext
attribute that the singleton support instance is stored in. -
CONTEXT_ATTRIBUTE
The attribute key for theServletContext
attribute that theLoggerContext
is stored in.
-
-
Method Details
-
setLoggerContext
void setLoggerContext()Sets the logger context so that code executing afterwards can easily and quickly access loggers viaLogManager.getLogger()
. -
clearLoggerContext
void clearLoggerContext()Clears the logger context set up insetLoggerContext()
. -
wrapExecution
Sets the logger context by callingsetLoggerContext()
, executes the runnable argument, then clears the logger context by callingclearLoggerContext()
.- Parameters:
runnable
- The runnable to execute wrapped with a configured logger context
-