Package org.apache.logging.log4j.web
Class Log4jWebInitializerImpl
java.lang.Object
org.apache.logging.log4j.core.AbstractLifeCycle
org.apache.logging.log4j.web.Log4jWebInitializerImpl
- All Implemented Interfaces:
LifeCycle
,LifeCycle2
,Log4jWebLifeCycle
,Log4jWebSupport
This class initializes and deinitializes Log4j no matter how the initialization occurs.
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate LoggerContext
private String
private NamedContextSelector
private final jakarta.servlet.ServletContext
private final StrSubstitutor
private static final String
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
Fields inherited from interface org.apache.logging.log4j.web.Log4jWebSupport
CONTEXT_ATTRIBUTE, IS_LOG4J_AUTO_INITIALIZATION_DISABLED, IS_LOG4J_AUTO_SHUTDOWN_DISABLED, IS_LOG4J_CONTEXT_SELECTOR_NAMED, LOG4J_CONFIG_LOCATION, LOG4J_CONTEXT_NAME, SUPPORT_ATTRIBUTE
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
Log4jWebInitializerImpl
(jakarta.servlet.ServletContext servletContext) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the logger context set up inLog4jWebSupport.setLoggerContext()
.private ClassLoader
private URI
getConfigURI
(String location) getConfigURIs
(String location) protected static Log4jWebInitializerImpl
initialize
(jakarta.servlet.ServletContext servletContext) Initializes the Log4jWebLifeCycle attribute of a ServletContext.private void
initializeJndi
(String location) private void
initializeNonJndi
(String location) private static String[]
Collects strings starting with the givenprefix
from the givenset
.void
Sets the logger context so that code executing afterwards can easily and quickly access loggers viaLogManager.getLogger()
.void
start()
Starts up Log4j in the web application.boolean
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.void
wrapExecution
(Runnable runnable) Sets the logger context by callingLog4jWebSupport.setLoggerContext()
, executes the runnable argument, then clears the logger context by callingLog4jWebSupport.clearLoggerContext()
.Methods inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
equalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stop, stop
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.logging.log4j.core.LifeCycle
getState, initialize, isStarted, isStopped
Methods inherited from interface org.apache.logging.log4j.web.Log4jWebLifeCycle
stop
-
Field Details
-
WEB_INF
- See Also:
-
map
-
substitutor
-
servletContext
private final jakarta.servlet.ServletContext servletContext -
name
-
namedContextSelector
-
loggerContext
-
-
Constructor Details
-
Log4jWebInitializerImpl
private Log4jWebInitializerImpl(jakarta.servlet.ServletContext servletContext)
-
-
Method Details
-
initialize
Initializes the Log4jWebLifeCycle attribute of a ServletContext. Those who wish to obtain this object should use theWebLoggerContextUtils.getWebLifeCycle(jakarta.servlet.ServletContext)
method instead.- Parameters:
servletContext
- the ServletContext to initialize- Returns:
- a new Log4jWebLifeCycle
- Since:
- 2.0.1
-
start
public void start()Description copied from interface:Log4jWebLifeCycle
Starts up Log4j in the web application. CallsLog4jWebSupport.setLoggerContext()
after initialization is complete.- Specified by:
start
in interfaceLifeCycle
- Specified by:
start
in interfaceLog4jWebLifeCycle
- Overrides:
start
in classAbstractLifeCycle
-
initializeJndi
-
initializeNonJndi
-
getConfigURIs
-
getConfigURI
-
prefixSet
Collects strings starting with the givenprefix
from the givenset
.- Parameters:
set
- a (nullable) set of stringsprefix
- a prefix to look for in the string set- Returns:
- an array of the matching strings from the given set
-
stop
Description copied from interface:LifeCycle2
Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.- Specified by:
stop
in interfaceLifeCycle2
- Overrides:
stop
in classAbstractLifeCycle
- Parameters:
timeout
- the maximum time to waittimeUnit
- the time unit of the timeout argument- Returns:
- true if the receiver was stopped cleanly and normally, false otherwise.
-
setLoggerContext
public void setLoggerContext()Description copied from interface:Log4jWebSupport
Sets the logger context so that code executing afterwards can easily and quickly access loggers viaLogManager.getLogger()
.- Specified by:
setLoggerContext
in interfaceLog4jWebSupport
-
clearLoggerContext
public void clearLoggerContext()Description copied from interface:Log4jWebSupport
Clears the logger context set up inLog4jWebSupport.setLoggerContext()
.- Specified by:
clearLoggerContext
in interfaceLog4jWebSupport
-
wrapExecution
Description copied from interface:Log4jWebSupport
Sets the logger context by callingLog4jWebSupport.setLoggerContext()
, executes the runnable argument, then clears the logger context by callingLog4jWebSupport.clearLoggerContext()
.- Specified by:
wrapExecution
in interfaceLog4jWebSupport
- Parameters:
runnable
- The runnable to execute wrapped with a configured logger context
-
getClassLoader
-