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 Details

    • LOG4J_CONTEXT_NAME

      static final String LOG4J_CONTEXT_NAME
      The ServletContext parameter name for the name of the LoggerContext.
      See Also:
    • LOG4J_CONFIG_LOCATION

      static final String LOG4J_CONFIG_LOCATION
      The ServletContext parameter name for the location of the configuration.
      See Also:
    • IS_LOG4J_CONTEXT_SELECTOR_NAMED

      static final String IS_LOG4J_CONTEXT_SELECTOR_NAMED
      The ServletContext parameter name for the JNDI flag.
      See Also:
    • IS_LOG4J_AUTO_INITIALIZATION_DISABLED

      static final 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. Set a context parameter with this name to "true" to disable auto-initialization.
      See Also:
    • IS_LOG4J_AUTO_SHUTDOWN_DISABLED

      static final 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. Set a context parameter with this name to "true" to disable auto-shutdown.
      See Also:
    • SUPPORT_ATTRIBUTE

      static final String SUPPORT_ATTRIBUTE
      The attribute key for the ServletContext attribute that the singleton support instance is stored in.
    • CONTEXT_ATTRIBUTE

      static final String CONTEXT_ATTRIBUTE
      The attribute key for the ServletContext attribute that the LoggerContext is stored in.
  • Method Details

    • setLoggerContext

      void setLoggerContext()
      Sets the logger context so that code executing afterwards can easily and quickly access loggers via LogManager.getLogger().
    • clearLoggerContext

      void clearLoggerContext()
      Clears the logger context set up in setLoggerContext().
    • wrapExecution

      void wrapExecution(Runnable runnable)
      Sets the logger context by calling setLoggerContext(), executes the runnable argument, then clears the logger context by calling clearLoggerContext().
      Parameters:
      runnable - The runnable to execute wrapped with a configured logger context