Logback Appender for Amazon CloudWatch

A Logback Classic 1.2 compatible appender that writes structured events to an Amazon CloudWatch log stream.

License

License

Categories

Categories

Logback Application Layer Libs Logging
GroupId

GroupId

com.xpcagey
ArtifactId

ArtifactId

logback-cloudwatch-appender
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Logback Appender for Amazon CloudWatch
A Logback Classic 1.2 compatible appender that writes structured events to an Amazon CloudWatch log stream.
Project URL

Project URL

https://github.com/xp-cagey/logback-cloudwatch-appender
Source Code Management

Source Code Management

https://github.com/xp-cagey/logback-cloudwatch-appender

Download logback-cloudwatch-appender

How to add to project

<!-- https://jarcasting.com/artifacts/com.xpcagey/logback-cloudwatch-appender/ -->
<dependency>
    <groupId>com.xpcagey</groupId>
    <artifactId>logback-cloudwatch-appender</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.xpcagey/logback-cloudwatch-appender/
implementation 'com.xpcagey:logback-cloudwatch-appender:1.0.0'
// https://jarcasting.com/artifacts/com.xpcagey/logback-cloudwatch-appender/
implementation ("com.xpcagey:logback-cloudwatch-appender:1.0.0")
'com.xpcagey:logback-cloudwatch-appender:jar:1.0.0'
<dependency org="com.xpcagey" name="logback-cloudwatch-appender" rev="1.0.0">
  <artifact name="logback-cloudwatch-appender" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.xpcagey', module='logback-cloudwatch-appender', version='1.0.0')
)
libraryDependencies += "com.xpcagey" % "logback-cloudwatch-appender" % "1.0.0"
[com.xpcagey/logback-cloudwatch-appender "1.0.0"]

Dependencies

compile (2)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.2.3
com.amazonaws : aws-java-sdk-logs jar 1.11.328

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
org.mockito : mockito-core jar 2.18.3

Project Modules

There are no modules declared in this project.

Logback Appender for Amazon CloudWatch

Build Status codecov Maven Central

This is an asynchronous implementation of a Logback appender that writes events to a specified Amazon CloudWatch log group. It requires Java 8+ to compile.

The logger will fail if the matching log group is not found, but will attempt to create a missing log stream within the group. This is designed to allow the creation of per-instance streams based on dynamic parameters inside of a cluster. You could accomplish this by either supplying a property inside your log definition or using a streamNameSupplier to inject the correct stream at generation time.

Configuration Parameters

Name Type Purpose Required?
encoder Logback Encoder describes a format for logged messages yes
groupName String name of the CloudWatch log group yes
streamName String name of the CloudWatch log stream no^
streamNameSupplier Supplier<String> source for CloudWatch log stream names no^
awsLogsSupplier Supplier<AWSLogs> source for a AWSLogs (CloudWatch) client no

^ either a streamName or a streamNameSupplier must be provided

Sample Configuration

<appender name="AWS-CLOUD-WATCH" class="com.xpcagey.logback.CloudWatchAppender">
    <encoder>
        <pattern>%-5level [%.15thread] %logger{0}: %msg%n</pattern>
    </encoder>
    <groupName>MyGroup</groupName>
    <streamName>MyStream</streamName>
</appender>

Note that the timestamp is not present here because it is logged as an external field by CloudWatch. An example of a full file can be found in the integration tests here

Versions

Version
1.0.0