public interface Log4jWebSupport
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
.
Modifier and Type | Field and Description |
---|---|
static String |
CONTEXT_ATTRIBUTE
The attribute key for the
ServletContext attribute that the LoggerContext
is stored in. |
static String |
IS_LOG4J_AUTO_INITIALIZATION_DISABLED
The
ServletContext parameter name for the flag that disables Log4j's auto-initialization
in Servlet 3.0+ web applications. |
static String |
IS_LOG4J_AUTO_SHUTDOWN_DISABLED
The
ServletContext parameter name for the flag that disables Log4j's auto-shutdown
in Servlet 3.0+ web applications. |
static String |
IS_LOG4J_CONTEXT_SELECTOR_NAMED
The
ServletContext parameter name for the JNDI flag. |
static String |
LOG4J_CONFIG_LOCATION
The
ServletContext parameter name for the location of the configuration. |
static String |
LOG4J_CONTEXT_NAME
The
ServletContext parameter name for the name of the
LoggerContext . |
static String |
SUPPORT_ATTRIBUTE
The attribute key for the
ServletContext attribute that the singleton support instance
is stored in. |
Modifier and Type | Method and Description |
---|---|
void |
clearLoggerContext()
Clears the logger context set up in
setLoggerContext() . |
void |
setLoggerContext()
Sets the logger context so that code executing afterwards can easily and quickly access loggers via
LogManager.getLogger() . |
void |
wrapExecution(Runnable runnable)
Sets the logger context by calling
setLoggerContext() , executes the runnable argument, then clears the
logger context by calling clearLoggerContext() . |
static final String LOG4J_CONTEXT_NAME
ServletContext
parameter name for the name of the
LoggerContext
.static final String LOG4J_CONFIG_LOCATION
ServletContext
parameter name for the location of the configuration.static final String IS_LOG4J_CONTEXT_SELECTOR_NAMED
ServletContext
parameter name for the JNDI flag.static final String IS_LOG4J_AUTO_INITIALIZATION_DISABLED
ServletContext
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.static final String IS_LOG4J_AUTO_SHUTDOWN_DISABLED
ServletContext
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.static final String SUPPORT_ATTRIBUTE
ServletContext
attribute that the singleton support instance
is stored in.static final String CONTEXT_ATTRIBUTE
ServletContext
attribute that the LoggerContext
is stored in.void setLoggerContext()
LogManager.getLogger()
.void clearLoggerContext()
setLoggerContext()
.void wrapExecution(Runnable runnable)
setLoggerContext()
, executes the runnable argument, then clears the
logger context by calling clearLoggerContext()
.runnable
- The runnable to execute wrapped with a configured logger contextCopyright © 1999-1969 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.