Class AsyncLoggerContext
- java.lang.Object
-
- org.apache.logging.log4j.core.AbstractLifeCycle
-
- org.apache.logging.log4j.core.LoggerContext
-
- org.apache.logging.log4j.core.async.AsyncLoggerContext
-
- All Implemented Interfaces:
java.lang.AutoCloseable,ConfigurationListener,LifeCycle,LifeCycle2,LoggerContext,LoggerContextShutdownEnabled,Terminable
public class AsyncLoggerContext extends LoggerContext
LoggerContextthat createsAsyncLoggerobjects.
-
-
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 AsyncLoggerDisruptorloggerDisruptor-
Fields inherited from class org.apache.logging.log4j.core.LoggerContext
PROPERTY_CONFIG
-
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.spi.LoggerContext
EMPTY_ARRAY
-
-
Constructor Summary
Constructors Constructor Description AsyncLoggerContext(java.lang.String name)AsyncLoggerContext(java.lang.String name, java.lang.Object externalContext)AsyncLoggerContext(java.lang.String name, java.lang.Object externalContext, java.lang.String configLocn)AsyncLoggerContext(java.lang.String name, java.lang.Object externalContext, java.net.URI configLocn)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RingBufferAdmincreateRingBufferAdmin()Creates and returns a newRingBufferAdminthat instruments the ringbuffer of theAsyncLoggerobjects in thisLoggerContext.private voidmaybeStartHelper(Configuration config)protected LoggernewInstance(LoggerContext ctx, java.lang.String name, MessageFactory messageFactory)Callback to create a new logger.voidsetName(java.lang.String name)Sets 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.booleanstop(long timeout, java.util.concurrent.TimeUnit timeUnit)Blocks 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, updateLoggers
-
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.spi.LoggerContext
getLogger, getLogger
-
-
-
-
Field Detail
-
loggerDisruptor
private final AsyncLoggerDisruptor loggerDisruptor
-
-
Constructor Detail
-
AsyncLoggerContext
public AsyncLoggerContext(java.lang.String name)
-
AsyncLoggerContext
public AsyncLoggerContext(java.lang.String name, java.lang.Object externalContext)
-
AsyncLoggerContext
public AsyncLoggerContext(java.lang.String name, java.lang.Object externalContext, java.net.URI configLocn)
-
AsyncLoggerContext
public AsyncLoggerContext(java.lang.String name, java.lang.Object externalContext, java.lang.String configLocn)
-
-
Method Detail
-
newInstance
protected Logger newInstance(LoggerContext ctx, java.lang.String name, MessageFactory messageFactory)
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
public void setName(java.lang.String name)
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
public void start(Configuration config)
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
-
maybeStartHelper
private void maybeStartHelper(Configuration config)
-
stop
public boolean stop(long timeout, java.util.concurrent.TimeUnit timeUnit)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
public RingBufferAdmin 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
-
-