Package org.apache.logging.log4j.web
Class WebLoggerContextUtils
- java.lang.Object
-
- org.apache.logging.log4j.web.WebLoggerContextUtils
-
public final class WebLoggerContextUtils extends java.lang.ObjectConvenience methods for retrieving theLoggerContextassociated with a particular ServletContext. These methods are most particularly useful for asynchronous servlets where the Thread Context ClassLoader (TCCL) is potentially different from the TCCL used by the Servlet container that bootstrapped Log4j.- Since:
- 2.0.1
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringSERVLET_CONTEXTprivate static java.util.concurrent.locks.LockWEB_SUPPORT_LOOKUP
-
Constructor Summary
Constructors Modifier Constructor Description privateWebLoggerContextUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Map.Entry<java.lang.String,java.lang.Object>createExternalEntry(jakarta.servlet.ServletContext servletContext)static LoggerContextgetRequiredWebLoggerContext(jakarta.servlet.ServletContext servletContext)Finds the mainLoggerContextconfigured for the given ServletContext.static jakarta.servlet.ServletContextgetServletContext()Gets the currentServletContextif it has already been assigned to a LoggerContext's external context.static Log4jWebLifeCyclegetWebLifeCycle(jakarta.servlet.ServletContext servletContext)Finds or initializes theLog4jWebLifeCyclesingleton for the given ServletContext.static LoggerContextgetWebLoggerContext(jakarta.servlet.ServletContext servletContext)Finds the mainLoggerContextconfigured for the given ServletContext.static voidsetServletContext(LoggerContext lc, jakarta.servlet.ServletContext servletContext)static java.lang.RunnablewrapExecutionContext(jakarta.servlet.ServletContext servletContext, java.lang.Runnable runnable)Wraps a Runnable instance by setting its thread contextLoggerContextbefore execution and clearing it after execution.
-
-
-
Field Detail
-
WEB_SUPPORT_LOOKUP
private static final java.util.concurrent.locks.Lock WEB_SUPPORT_LOOKUP
-
SERVLET_CONTEXT
private static final java.lang.String SERVLET_CONTEXT
- See Also:
- Constant Field Values
-
-
Method Detail
-
getWebLoggerContext
public static LoggerContext getWebLoggerContext(jakarta.servlet.ServletContext servletContext)
Finds the mainLoggerContextconfigured for the given ServletContext.- Parameters:
servletContext- the ServletContext to locate a LoggerContext for- Returns:
- the LoggerContext for the given ServletContext
- Since:
- 2.0.1
-
getRequiredWebLoggerContext
public static LoggerContext getRequiredWebLoggerContext(jakarta.servlet.ServletContext servletContext)
Finds the mainLoggerContextconfigured for the given ServletContext.- Parameters:
servletContext- the ServletContext to locate a LoggerContext for- Returns:
- the LoggerContext for the given ServletContext or
nullif none was set - Throws:
java.lang.IllegalStateException- if no LoggerContext could be found on the given ServletContext- Since:
- 2.0.1
-
getWebLifeCycle
public static Log4jWebLifeCycle getWebLifeCycle(jakarta.servlet.ServletContext servletContext)
Finds or initializes theLog4jWebLifeCyclesingleton for the given ServletContext.- Parameters:
servletContext- the ServletContext to get the Log4jWebLifeCycle for- Returns:
- the Log4jWebLifeCycle for the given ServletContext
- Since:
- 2.0.1
-
wrapExecutionContext
public static java.lang.Runnable wrapExecutionContext(jakarta.servlet.ServletContext servletContext, java.lang.Runnable runnable)Wraps a Runnable instance by setting its thread contextLoggerContextbefore execution and clearing it after execution.- Parameters:
servletContext- the ServletContext to locate a LoggerContext forrunnable- the Runnable to wrap execution for- Returns:
- a wrapped Runnable
- Since:
- 2.0.1
-
createExternalEntry
public static java.util.Map.Entry<java.lang.String,java.lang.Object> createExternalEntry(jakarta.servlet.ServletContext servletContext)
-
setServletContext
public static void setServletContext(LoggerContext lc, jakarta.servlet.ServletContext servletContext)
-
getServletContext
public static jakarta.servlet.ServletContext getServletContext()
Gets the currentServletContextif it has already been assigned to a LoggerContext's external context.- Returns:
- the current ServletContext attached to a LoggerContext or
nullif none could be found - Since:
- 2.1
-
-