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 LoggerContext
loggerContext
private java.util.Map<java.lang.String,java.lang.String>
map
private java.lang.String
name
private NamedContextSelector
namedContextSelector
private jakarta.servlet.ServletContext
servletContext
private StrSubstitutor
substitutor
private static java.lang.String
WEB_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 private
Log4jWebInitializerImpl(jakarta.servlet.ServletContext servletContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clearLoggerContext()
Clears the logger context set up inLog4jWebSupport.setLoggerContext()
.private java.lang.ClassLoader
getClassLoader()
private java.net.URI
getConfigURI(java.lang.String location)
private java.util.List<java.net.URI>
getConfigURIs(java.lang.String location)
protected static Log4jWebInitializerImpl
initialize(jakarta.servlet.ServletContext servletContext)
Initializes the Log4jWebLifeCycle attribute of a ServletContext.private void
initializeJndi(java.lang.String location)
private void
initializeNonJndi(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 givenprefix
from the givenset
.void
setLoggerContext()
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
stop(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.void
wrapExecution(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: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
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 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
public boolean stop(long timeout, java.util.concurrent.TimeUnit timeUnit)
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
public void wrapExecution(java.lang.Runnable runnable)
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
private java.lang.ClassLoader getClassLoader()
-
-