Package org.apache.logging.log4j.web
Interface Log4jWebSupport
-
public interface Log4jWebSupport
Specifies an interface for setting and clearing a thread-boundLoggerContext
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 withsetLoggerContext()
andclearLoggerContext()
.You can obtain the instance of this for your web application by retrieving the
ServletContext
attribute namedorg.apache.logging.log4j.core.web.Log4jWebSupport.INSTANCE
. If needed, you can also obtain theLoggerContext
instance for your web application by retrieving theServletContext
attribute namedorg.apache.logging.log4j.spi.LoggerContext.INSTANCE
.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CONTEXT_ATTRIBUTE
The attribute key for theServletContext
attribute that theLoggerContext
is stored in.static java.lang.String
IS_LOG4J_AUTO_INITIALIZATION_DISABLED
TheServletContext
parameter name for the flag that disables Log4j's auto-initialization in Servlet 3.0+ web applications.static java.lang.String
IS_LOG4J_CONTEXT_SELECTOR_NAMED
TheServletContext
parameter name for the JNDI flag.static java.lang.String
LOG4J_CONFIG_LOCATION
TheServletContext
parameter name for the location of the configuration.static java.lang.String
LOG4J_CONTEXT_NAME
TheServletContext
parameter name for the name of theLoggerContext
.static java.lang.String
SUPPORT_ATTRIBUTE
The attribute key for theServletContext
attribute that the singleton support instance is stored in.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clearLoggerContext()
Clears the logger context set up insetLoggerContext()
.void
setLoggerContext()
Sets the logger context so that code executing afterwards can easily and quickly access loggers viaLogManager.getLogger()
.void
wrapExecution(java.lang.Runnable runnable)
Sets the logger context by callingsetLoggerContext()
, executes the runnable argument, then clears the logger context by callingclearLoggerContext()
.
-
-
-
Field Detail
-
LOG4J_CONTEXT_NAME
static final java.lang.String LOG4J_CONTEXT_NAME
TheServletContext
parameter name for the name of theLoggerContext
.- See Also:
- Constant Field Values
-
LOG4J_CONFIG_LOCATION
static final java.lang.String LOG4J_CONFIG_LOCATION
TheServletContext
parameter name for the location of the configuration.- See Also:
- Constant Field Values
-
IS_LOG4J_CONTEXT_SELECTOR_NAMED
static final java.lang.String IS_LOG4J_CONTEXT_SELECTOR_NAMED
TheServletContext
parameter name for the JNDI flag.- See Also:
- Constant Field Values
-
IS_LOG4J_AUTO_INITIALIZATION_DISABLED
static final java.lang.String 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:
- Constant Field Values
-
SUPPORT_ATTRIBUTE
static final java.lang.String SUPPORT_ATTRIBUTE
The attribute key for theServletContext
attribute that the singleton support instance is stored in.
-
CONTEXT_ATTRIBUTE
static final java.lang.String CONTEXT_ATTRIBUTE
The attribute key for theServletContext
attribute that theLoggerContext
is stored in.
-
-
Method Detail
-
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
void wrapExecution(java.lang.Runnable runnable)
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
-
-