public class CloudWatchClassicAppender
extends ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
Appender interface with a connection to Amazon
CloudWatch for Logback classic implementations. This class is a lightweight wrapper around a
CloudWatchWorker that pushes appended ILoggingEvents into a BlockingQueue for
asynchronous processing.
If you will be using this appender in a cluster, it is *strongly recommended* that you use the
setStreamNameSupplier interface to give each process a unique log stream name inside of your log group.
This code attempts to correct for stream write collisions, but the Amazon CloudWatch system expects that each log
producer has a distinct stream and this appender will need to retry every send that is written after another process
has touched a stream.ILoggingEvent,
Encoder| Constructor and Description |
|---|
CloudWatchClassicAppender() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
append(ch.qos.logback.classic.spi.ILoggingEvent event)
Calling this function will ship the event to AWSLogs
|
void |
setAWSLogsSupplier(Supplier<com.amazonaws.services.logs.AWSLogs> supplier)
Allows injection of an
AWSLogs that is built using custom credentials. |
void |
setEncoder(ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent> encoder)
Sets the encoder to be used by this logging system; any encoder that is legal for an OutputStreamAppender may
also be used here.
|
void |
setGroupName(String groupName)
Sets a static group name; if this group is not present an exception will be thrown during start().
|
void |
setStreamName(String streamName)
Sets a static stream name; if this group is not present in the AWS account it will be manually created.
|
void |
setStreamNameSupplier(Supplier<String> source)
Allows injection of a custom stream name creator that can use fields like IP address or EC2 instance id to
provide a unique stream name for each member of a cluster.
|
void |
start()
Called by Logback during startup or reset; attempts to connect to AWSLogs and either create or use a log stream.
|
void |
stop()
Called by Logback during reset or shutdown; safely tears down the connection to AWSLogs
|
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, toStringaddError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContextpublic void setEncoder(ch.qos.logback.core.encoder.Encoder<ch.qos.logback.classic.spi.ILoggingEvent> encoder)
encoder - the encoder to use for loggingpublic void setGroupName(String groupName)
groupName - group name passed through the AWSLogs APIpublic void setStreamName(String streamName)
streamName - stream name passed through the AWSLogs APIpublic void setStreamNameSupplier(Supplier<String> source)
source - generator for the stream name to use for this instancepublic void setAWSLogsSupplier(Supplier<com.amazonaws.services.logs.AWSLogs> supplier)
AWSLogs that is built using custom credentials.supplier - the overloaded supplier that will be used to construct the worker at startupAWSLogspublic void start()
start in interface ch.qos.logback.core.spi.LifeCyclestart in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>IllegalArgumentException - if the group name or stream name is rejected by Amazon CloudWatch or the encoder
has not been setcom.amazonaws.services.logs.model.ResourceNotFoundException - if the log group has not been created in Amazon CloudWatchpublic void stop()
stop in interface ch.qos.logback.core.spi.LifeCyclestop in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>protected void append(ch.qos.logback.classic.spi.ILoggingEvent event)
append in class ch.qos.logback.core.UnsynchronizedAppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>Copyright © 2018. All rights reserved.