Class AsyncLoggerContext
- All Implemented Interfaces:
AutoCloseable,ConfigurationListener,LifeCycle,LifeCycle2,LoggerContext,LoggerContextShutdownEnabled,Terminable
LoggerContext that creates AsyncLogger objects.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.apache.logging.log4j.core.LifeCycle
LifeCycle.State -
Field Summary
Fields inherited from class org.apache.logging.log4j.core.LoggerContext
PROPERTY_CONFIGFields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGERFields inherited from interface org.apache.logging.log4j.spi.LoggerContext
EMPTY_ARRAY -
Constructor Summary
ConstructorsConstructorDescriptionAsyncLoggerContext(String name) AsyncLoggerContext(String name, Object externalContext) AsyncLoggerContext(String name, Object externalContext, String configLocn) AsyncLoggerContext(String name, Object externalContext, URI configLocn) -
Method Summary
Modifier and TypeMethodDescriptionCreates and returns a newRingBufferAdminthat instruments the ringbuffer of theAsyncLoggerobjects in thisLoggerContext.protected LoggernewInstance(LoggerContext ctx, String name, MessageFactory messageFactory) Callback to create a new logger.voidSets the name.voidsetUseThreadLocals(boolean useThreadLocals) Signals this context whether it is allowed to use ThreadLocal objects for efficiency.voidstart()Starts the context using the configuration specified byLoggerContext.getConfigLocation().voidstart(Configuration config) Starts the context using a specific configuration.booleanBlocks until all Log4j tasks have completed execution after a shutdown request and all appenders have shut down, or the timeout occurs, or the current thread is interrupted, whichever happens first.Methods inherited from class org.apache.logging.log4j.core.LoggerContext
addFilter, addPropertyChangeListener, addShutdownListener, close, getConfigLocation, getConfiguration, getContext, getContext, getContext, getExternalContext, getListeners, getLogger, getLogger, getLoggerRegistry, getLoggers, getName, getObject, getRootLogger, hasLogger, hasLogger, hasLogger, onChange, putObject, putObjectIfAbsent, reconfigure, reconfigure, removeFilter, removeObject, removeObject, removePropertyChangeListener, setConfigLocation, setConfiguration, setExternalContext, terminate, updateLoggers, updateLoggersMethods 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.spi.LoggerContext
getLogger, getLogger
-
Constructor Details
-
AsyncLoggerContext
-
AsyncLoggerContext
-
AsyncLoggerContext
-
AsyncLoggerContext
-
-
Method Details
-
newInstance
Description copied from class:LoggerContextCallback to create a new logger.- Overrides:
newInstancein classLoggerContext- Parameters:
ctx- TheLoggerContextthis logger is associated with, nevernull.name- The logger name, nevernull.messageFactory- The message factory to be used, nevernull.- Returns:
- A new logger instance.
-
setName
Description copied from class:LoggerContextSets the name.- Overrides:
setNamein classLoggerContext- Parameters:
name- the new LoggerContext name
-
start
public void start()Description copied from class:LoggerContextStarts the context using the configuration specified byLoggerContext.getConfigLocation().If the configuration location is
null, Log4j will search for a configuration file using the default classpath resources. For details on the search order and supported formats, see the Log4j 2 Configuration File Location documentation.- Specified by:
startin interfaceLifeCycle- Overrides:
startin classLoggerContext
-
start
Description copied from class:LoggerContextStarts the context using a specific configuration.Warning: For backward compatibility, especially with Spring Boot, if the context is already started, this method will fall back to
LoggerContext.reconfigure(Configuration). This behavior is maintained for legacy integrations and may change in future major versions. New code should not rely on this fallback.- Overrides:
startin classLoggerContext- Parameters:
config- The newConfigurationto use for this context
-
stop
Description copied from class:LoggerContextBlocks until all Log4j tasks have completed execution after a shutdown request and all appenders have shut down, or the timeout occurs, or the current thread is interrupted, whichever happens first.Not all appenders will honor this, it is a hint and not an absolute guarantee that the this method not block longer. Setting timeout too low increase the risk of losing outstanding log events not yet written to the final destination.
Log4j can start threads to perform certain actions like file rollovers, calling this method with a positive timeout will block until the rollover thread is done.
- Specified by:
stopin interfaceLifeCycle2- Overrides:
stopin classLoggerContext- Parameters:
timeout- the maximum time to wait, or 0 which mean that each apppender uses its default timeout, and don't wait for background taskstimeUnit- the time unit of the timeout argument- Returns:
trueif the logger context terminated andfalseif the timeout elapsed before termination.
-
createRingBufferAdmin
Creates and returns a newRingBufferAdminthat instruments the ringbuffer of theAsyncLoggerobjects in thisLoggerContext.- Returns:
- a new
RingBufferAdminthat instruments the ringbuffer
-
setUseThreadLocals
public void setUseThreadLocals(boolean useThreadLocals) Signals this context whether it is allowed to use ThreadLocal objects for efficiency.- Parameters:
useThreadLocals- whether this context is allowed to use ThreadLocal objects
-