public abstract class AbstractAppender<WriterConfigType,AppenderStatsType extends AbstractWriterStatistics,AppenderStatsMXBeanType,LogbackEventType>
extends ch.qos.logback.core.UnsynchronizedAppenderBase<LogbackEventType>
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.
Some behaviors, such as log rotation, are implemented here even if they are not
supported by all appenders. The appenders that do not support those behaviors are
responsible for disabling them. For example, an appender that does not support log
rotation should throw if setRotationMode(java.lang.String) is called.
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, well, this is an internal class: they may go away.
Note: this appender is built on UnsynchronizedAppenderBase, which is
perhaps unnecessary (if you're worried about contention you shouldn't be doing a
lot of logging). However, there are some critical sections within append(LogbackEventType),
and these are protected by internal lock objects.
| Modifier and Type | Field and Description |
|---|---|
protected AppenderStatsType |
appenderStats |
protected String |
assumedRole |
protected long |
batchDelay |
protected String |
clientEndpoint |
protected String |
clientFactory |
protected String |
clientRegion |
protected DiscardAction |
discardAction |
protected int |
discardThreshold |
protected InternalLogger |
internalLogger |
protected long |
lastRotationTimestamp |
protected ch.qos.logback.core.Layout<LogbackEventType> |
layout |
protected int |
messagesSinceLastRotation |
protected long |
rotationInterval |
protected RotationMode |
rotationMode |
protected AtomicInteger |
sequence |
protected boolean |
synchronous |
protected ThreadFactory |
threadFactory |
protected boolean |
truncateOversizeMessages |
protected boolean |
useShutdownHook |
protected LogWriter |
writer |
protected WriterFactory<WriterConfigType,AppenderStatsType> |
writerFactory |
| Constructor and Description |
|---|
AbstractAppender(ThreadFactory threadFactory,
WriterFactory<WriterConfigType,AppenderStatsType> writerFactory,
AppenderStatsType appenderStats,
Class<AppenderStatsMXBeanType> appenderStatsMXBeanClass) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
append(LogbackEventType event) |
protected abstract WriterConfigType |
generateWriterConfig()
Called just before a writer is created, so that the subclass can
perform substitutions on the configuration.
|
AppenderStatsType |
getAppenderStatistics()
Returns the appender statistics object.
|
String |
getAssumedRole()
Returns the
assumedRole configuration property. |
long |
getBatchDelay()
Returns the
batchDelay configuration property. |
String |
getClientEndpoint()
Returns the
clientEndpoint configuration property. |
String |
getClientFactory()
Returns the
clientFactory configuration property. |
String |
getClientRegion()
Returns the
clientRegion configuration property. |
String |
getDiscardAction()
Returns the
discardAction configuration property. |
int |
getDiscardThreshold()
Returns the
discardThreshold configuration property. |
long |
getRotationInterval()
Returns the
rotationInterval configuration property. |
String |
getRotationMode()
Returns the
rotationMode configuration property. |
int |
getSequence()
Returns the current
sequence value (which will be updated each
time the appender rotates). |
boolean |
getSynchronous()
Returns the
synchronous configuration property. |
boolean |
getTruncateOversizeMessages()
Returns the
truncateOversizeMessages configuration property. |
boolean |
getUseShutdownHook()
Returns the
useShutdownHook configuration property. |
protected void |
registerStatisticsBean()
Registers the appender statistics with JMX.
|
protected void |
rotate()
Rotates the log writer.
|
void |
setAssumedRole(String value)
Sets the
assumedRole configuration property. |
void |
setBatchDelay(long value)
Sets the
batchDelay configuration property. |
void |
setClientEndpoint(String value)
Sets the
clientEndpoint configuration property. |
void |
setClientFactory(String value)
Sets the
discardAction configuration property. |
void |
setClientRegion(String value)
Sets the
clientRegion configuration property. |
void |
setDiscardAction(String value)
Sets the
discardAction configuration property. |
void |
setDiscardThreshold(int value)
Sets the
discardThreshold configuration property. |
void |
setLayout(ch.qos.logback.core.Layout<LogbackEventType> layout)
Sets the layout manager for this appender.
|
void |
setName(String name) |
void |
setRotationInterval(long value)
Sets the
rotationInterval configuration property. |
protected void |
setRotationMode(String value)
Sets the
rotationMode configuration property. |
void |
setSequence(int value)
Sets the
sequence configuration property. |
void |
setSynchronous(boolean value)
Sets the
synchronous configuration property. |
void |
setTruncateOversizeMessages(boolean value)
Sets the
truncateOversizeMessages configuration property. |
void |
setUseShutdownHook(boolean value)
Sets the
useShutdownHook configuration property. |
protected boolean |
shouldRotate(long now)
Determines whether the appender should rotate its writer.
|
void |
start() |
void |
stop() |
protected void |
unregisterStatisticsBean()
Unregisters the appender statistics from JMX.
|
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, toStringaddError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextprotected ThreadFactory threadFactory
protected WriterFactory<WriterConfigType,AppenderStatsType extends AbstractWriterStatistics> writerFactory
protected InternalLogger internalLogger
protected AppenderStatsType extends AbstractWriterStatistics appenderStats
protected volatile LogWriter writer
protected ch.qos.logback.core.Layout<LogbackEventType> layout
protected volatile long lastRotationTimestamp
protected volatile int messagesSinceLastRotation
protected boolean synchronous
protected long batchDelay
protected boolean truncateOversizeMessages
protected int discardThreshold
protected DiscardAction discardAction
protected volatile RotationMode rotationMode
protected volatile long rotationInterval
protected AtomicInteger sequence
protected String assumedRole
protected String clientFactory
protected String clientRegion
protected String clientEndpoint
protected boolean useShutdownHook
public AbstractAppender(ThreadFactory threadFactory, WriterFactory<WriterConfigType,AppenderStatsType> writerFactory, AppenderStatsType appenderStats, Class<AppenderStatsMXBeanType> appenderStatsMXBeanClass)
public void setName(String name)
setName in interface ch.qos.logback.core.Appender<LogbackEventType>setName in class ch.qos.logback.core.UnsynchronizedAppenderBase<LogbackEventType>public void setLayout(ch.qos.logback.core.Layout<LogbackEventType> layout)
Encoder; it is a knob that doesn't need to be turned.protected void setRotationMode(String value)
rotationMode configuration property.
This method must be explicitly overridden and made public by appenders that support rotation.
public String getRotationMode()
rotationMode configuration property.public void setRotationInterval(long value)
rotationInterval configuration property.public long getRotationInterval()
rotationInterval configuration property.public void setSequence(int value)
sequence configuration property.public int getSequence()
sequence value (which will be updated each
time the appender rotates).public void setSynchronous(boolean value)
synchronous configuration property. This can only
be done at the time of configuration, not once the appender is operating.public boolean getSynchronous()
synchronous configuration property.public void setBatchDelay(long value)
batchDelay configuration property.public long getBatchDelay()
batchDelay configuration property.public void setTruncateOversizeMessages(boolean value)
truncateOversizeMessages configuration property.public boolean getTruncateOversizeMessages()
truncateOversizeMessages configuration property.public void setDiscardThreshold(int value)
discardThreshold configuration property.public int getDiscardThreshold()
discardThreshold configuration property.public void setDiscardAction(String value)
discardAction configuration property.public String getDiscardAction()
discardAction configuration property.public void setAssumedRole(String value)
assumedRole configuration property.
Calling this method after the writer has been initialized will have no effect until the next log rotation.
public String getAssumedRole()
assumedRole configuration property.public void setClientFactory(String value)
discardAction configuration property.
Calling this method after the writer has been initialized will have no effect until the next log rotation.
public String getClientFactory()
clientFactory configuration property.public void setClientRegion(String value)
clientRegion configuration property.public String getClientRegion()
clientRegion configuration property.public void setClientEndpoint(String value)
clientEndpoint configuration property.public String getClientEndpoint()
clientEndpoint configuration property.public void setUseShutdownHook(boolean value)
useShutdownHook configuration property.public boolean getUseShutdownHook()
useShutdownHook configuration property.public AppenderStatsType getAppenderStatistics()
public void start()
start in interface ch.qos.logback.core.spi.LifeCyclestart in class ch.qos.logback.core.UnsynchronizedAppenderBase<LogbackEventType>public void stop()
stop in interface ch.qos.logback.core.spi.LifeCyclestop in class ch.qos.logback.core.UnsynchronizedAppenderBase<LogbackEventType>protected void append(LogbackEventType event)
append in class ch.qos.logback.core.UnsynchronizedAppenderBase<LogbackEventType>protected void rotate()
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.
Note: this method is protected so that it can be avoided during unit tests.
protected void unregisterStatisticsBean()
Note: this method is protected so that it can be avoided during unit tests.
protected boolean shouldRotate(long now)
Copyright © 2020. All rights reserved.