public abstract class AbstractAppender<WriterConfigType extends AbstractWriterConfig<WriterConfigType>,AppenderConfigType extends AbstractAppenderConfig,AppenderStatsType extends AbstractWriterStatistics,AppenderStatsMXBeanType>
extends org.apache.logging.log4j.core.appender.AbstractAppender
For the most part, appenders have the same behavior: they initialize, transform log messages, and shut down. Most of the code to do that lives here, with a few hooks that are implemented in the appender proper.
Most of the member variables defined by this class are protected. This is intended to support testing. If you decide to subclass and access those variables, remember that this is an internal class: they may go away.
Log4J2, like Logback, explicitly initializes the appender before use. The only strangeness here is in stop(): there are two versions defined by the interface, but current versions of Log4J call only one of them.
| Modifier and Type | Field and Description |
|---|---|
protected AppenderConfigType |
appenderConfig |
protected AppenderStatsType |
appenderStats |
protected MessageQueue.DiscardAction |
discardAction |
protected InternalLogger |
internalLogger |
protected Charset |
layoutCharset |
protected ThreadFactory |
threadFactory |
protected LogWriter |
writer |
protected WriterFactory<WriterConfigType,AppenderStatsType> |
writerFactory |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractAppender(String name,
ThreadFactory threadFactory,
WriterFactory<WriterConfigType,AppenderStatsType> writerFactory,
AppenderStatsType appenderStats,
Class<AppenderStatsMXBeanType> appenderStatsMXBeanClass,
AppenderConfigType config,
InternalLogger providedInternalLogger) |
| Modifier and Type | Method and Description |
|---|---|
void |
append(org.apache.logging.log4j.core.LogEvent event) |
protected abstract WriterConfigType |
generateWriterConfig()
Called as part of initialization.
|
AppenderStatsType |
getAppenderStatistics()
Returns the appender statistics object.
|
AppenderConfigType |
getConfig()
Exposes configuration for testing.
|
protected void |
registerStatisticsBean()
Registers the appender statistics with JMX.
|
void |
start() |
void |
stop() |
boolean |
stop(long timeout,
TimeUnit timeUnit) |
protected void |
unregisterStatisticsBean()
Unregisters the appender statistics from JMX.
|
error, error, error, getHandler, getLayout, getName, ignoreExceptions, parseInt, setHandler, toStringaddFilter, getFilter, hasFilter, isFiltered, removeFilter, stopequalsImpl, getState, getStatusLogger, hashCodeImpl, initialize, isInitialized, isStarted, isStarting, isStopped, isStopping, setStarted, setStarting, setState, setStopped, setStopping, stopprotected ThreadFactory threadFactory
protected WriterFactory<WriterConfigType extends AbstractWriterConfig<WriterConfigType>,AppenderStatsType extends AbstractWriterStatistics> writerFactory
protected InternalLogger internalLogger
protected AppenderStatsType extends AbstractWriterStatistics appenderStats
protected AppenderConfigType extends AbstractAppenderConfig appenderConfig
protected Charset layoutCharset
protected MessageQueue.DiscardAction discardAction
protected volatile LogWriter writer
protected AbstractAppender(String name, ThreadFactory threadFactory, WriterFactory<WriterConfigType,AppenderStatsType> writerFactory, AppenderStatsType appenderStats, Class<AppenderStatsMXBeanType> appenderStatsMXBeanClass, AppenderConfigType config, InternalLogger providedInternalLogger)
public AppenderStatsType getAppenderStatistics()
public AppenderConfigType getConfig()
public void start()
start in interface org.apache.logging.log4j.core.LifeCyclestart in class org.apache.logging.log4j.core.filter.AbstractFilterablepublic void stop()
stop in interface org.apache.logging.log4j.core.LifeCyclestop in class org.apache.logging.log4j.core.AbstractLifeCyclepublic boolean stop(long timeout,
TimeUnit timeUnit)
stop in interface org.apache.logging.log4j.core.LifeCycle2stop in class org.apache.logging.log4j.core.filter.AbstractFilterablepublic void append(org.apache.logging.log4j.core.LogEvent event)
protected abstract WriterConfigType generateWriterConfig()
protected void registerStatisticsBean()
The name for the bean is consistent with the Log4J LayoutDynamicMBean,
so that it will appear in the hierarchy under the appender.
protected void unregisterStatisticsBean()
Copyright © 2022. All rights reserved.