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:
AutoCloseable
,ConfigurationListener
,LifeCycle
,LifeCycle2
,LoggerContext
,LoggerContextShutdownEnabled
,Terminable
public class AsyncLoggerContext extends LoggerContext
LoggerContext
that createsAsyncLogger
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_CONFIG
-
Fields inherited from class org.apache.logging.log4j.core.AbstractLifeCycle
DEFAULT_STOP_TIMEOUT, DEFAULT_STOP_TIMEUNIT, LOGGER
-
-
Constructor Summary
Constructors Constructor Description AsyncLoggerContext(String name)
AsyncLoggerContext(String name, Object externalContext)
AsyncLoggerContext(String name, Object externalContext, String configLocn)
AsyncLoggerContext(String name, Object externalContext, URI configLocn)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description RingBufferAdmin
createRingBufferAdmin()
Creates and returns a newRingBufferAdmin
that instruments the ringbuffer of theAsyncLogger
objects in thisLoggerContext
.protected Logger
newInstance(LoggerContext ctx, String name, MessageFactory messageFactory)
void
setName(String name)
Sets the name.void
setUseThreadLocals(boolean useThreadLocals)
Signals this context whether it is allowed to use ThreadLocal objects for efficiency.void
start()
void
start(Configuration config)
Starts with a specific configuration.boolean
stop(long timeout, 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, 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
-
-
-
-
Constructor Detail
-
AsyncLoggerContext
public AsyncLoggerContext(String name)
-
-
Method Detail
-
newInstance
protected Logger newInstance(LoggerContext ctx, String name, MessageFactory messageFactory)
- Overrides:
newInstance
in classLoggerContext
-
setName
public void setName(String name)
Description copied from class:LoggerContext
Sets the name.- Overrides:
setName
in classLoggerContext
- Parameters:
name
- the new LoggerContext name
-
start
public void start()
- Specified by:
start
in interfaceLifeCycle
- Overrides:
start
in classLoggerContext
-
start
public void start(Configuration config)
Description copied from class:LoggerContext
Starts with a specific configuration.- Overrides:
start
in classLoggerContext
- Parameters:
config
- The new Configuration.
-
stop
public boolean stop(long timeout, TimeUnit timeUnit)
Description copied from class:LoggerContext
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.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:
stop
in interfaceLifeCycle2
- Overrides:
stop
in 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:
true
if the logger context terminated andfalse
if the timeout elapsed before termination.
-
createRingBufferAdmin
public RingBufferAdmin createRingBufferAdmin()
Creates and returns a newRingBufferAdmin
that instruments the ringbuffer of theAsyncLogger
objects in thisLoggerContext
.- Returns:
- a new
RingBufferAdmin
that 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
-
-