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
final class Log4jWebInitializerImpl extends AbstractLifeCycle implements Log4jWebLifeCycle
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
Fields Modifier and Type Field Description private LoggerContextloggerContextprivate java.util.Map<java.lang.String,java.lang.String>mapprivate java.lang.Stringnameprivate NamedContextSelectornamedContextSelectorprivate jakarta.servlet.ServletContextservletContextprivate StrSubstitutorsubstitutorprivate static java.lang.StringWEB_INF-
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
Constructors Modifier Constructor Description privateLog4jWebInitializerImpl(jakarta.servlet.ServletContext servletContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclearLoggerContext()Clears the logger context set up inLog4jWebSupport.setLoggerContext().private java.lang.ClassLoadergetClassLoader()private java.net.URIgetConfigURI(java.lang.String location)private java.util.List<java.net.URI>getConfigURIs(java.lang.String location)protected static Log4jWebInitializerImplinitialize(jakarta.servlet.ServletContext servletContext)Initializes the Log4jWebLifeCycle attribute of a ServletContext.private voidinitializeJndi(java.lang.String location)private voidinitializeNonJndi(java.lang.String location)private static java.lang.String[]prefixSet(java.util.Set<java.lang.String> set, java.lang.String prefix)Collects strings starting with the givenprefixfrom the givenset.voidsetLoggerContext()Sets the logger context so that code executing afterwards can easily and quickly access loggers viaLogManager.getLogger().voidstart()Starts up Log4j in the web application.booleanstop(long timeout, java.util.concurrent.TimeUnit timeUnit)Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.voidwrapExecution(java.lang.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 Detail
-
WEB_INF
private static final java.lang.String WEB_INF
- See Also:
- Constant Field Values
-
map
private final java.util.Map<java.lang.String,java.lang.String> map
-
substitutor
private final StrSubstitutor substitutor
-
servletContext
private final jakarta.servlet.ServletContext servletContext
-
name
private java.lang.String name
-
namedContextSelector
private NamedContextSelector namedContextSelector
-
loggerContext
private LoggerContext loggerContext
-
-
Method Detail
-
initialize
protected static Log4jWebInitializerImpl initialize(jakarta.servlet.ServletContext servletContext)
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
private void initializeJndi(java.lang.String location)
-
initializeNonJndi
private void initializeNonJndi(java.lang.String location)
-
getConfigURIs
private java.util.List<java.net.URI> getConfigURIs(java.lang.String location)
-
getConfigURI
private java.net.URI getConfigURI(java.lang.String location)
-
prefixSet
private static java.lang.String[] prefixSet(java.util.Set<java.lang.String> set, java.lang.String prefix)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
public boolean stop(long timeout, java.util.concurrent.TimeUnit timeUnit)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
public void wrapExecution(java.lang.Runnable runnable)
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
private java.lang.ClassLoader getClassLoader()
-
-