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 LoggerContextprivate Stringprivate NamedContextSelectorprivate final jakarta.servlet.ServletContextprivate final StrSubstitutorprivate static final StringFields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGERFields 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
ConstructorsModifierConstructorDescriptionprivateLog4jWebInitializerImpl(jakarta.servlet.ServletContext servletContext) -
Method Summary
Modifier and TypeMethodDescriptionvoidClears the logger context set up inLog4jWebSupport.setLoggerContext().private ClassLoaderprivate URIgetConfigURI(String location) getConfigURIs(String location) protected static Log4jWebInitializerImplinitialize(jakarta.servlet.ServletContext servletContext) Initializes the Log4jWebLifeCycle attribute of a ServletContext.private voidinitializeJndi(String location) private voidinitializeNonJndi(String location) private static String[]Collects strings starting with the givenprefixfrom the givenset.voidSets the logger context so that code executing afterwards can easily and quickly access loggers viaLogManager.getLogger().voidstart()Starts up Log4j in the web application.booleanBlocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.voidwrapExecution(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, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.logging.log4j.core.LifeCycle
getState, initialize, isStarted, isStoppedMethods 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:Log4jWebLifeCycleStarts up Log4j in the web application. CallsLog4jWebSupport.setLoggerContext()after initialization is complete.- Specified by:
startin interfaceLifeCycle- Specified by:
startin interfaceLog4jWebLifeCycle- Overrides:
startin classAbstractLifeCycle
-
initializeJndi
-
initializeNonJndi
-
getConfigURIs
-
getConfigURI
-
prefixSet
Collects strings starting with the givenprefixfrom 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:LifeCycle2Blocks 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:
stopin interfaceLifeCycle2- Overrides:
stopin 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:Log4jWebSupportSets the logger context so that code executing afterwards can easily and quickly access loggers viaLogManager.getLogger().- Specified by:
setLoggerContextin interfaceLog4jWebSupport
-
clearLoggerContext
public void clearLoggerContext()Description copied from interface:Log4jWebSupportClears the logger context set up inLog4jWebSupport.setLoggerContext().- Specified by:
clearLoggerContextin interfaceLog4jWebSupport
-
wrapExecution
Description copied from interface:Log4jWebSupportSets the logger context by callingLog4jWebSupport.setLoggerContext(), executes the runnable argument, then clears the logger context by callingLog4jWebSupport.clearLoggerContext().- Specified by:
wrapExecutionin interfaceLog4jWebSupport- Parameters:
runnable- The runnable to execute wrapped with a configured logger context
-
getClassLoader
-