Skip to content
An Amazon Web Services (AWS) Logs (CloudWatch) appender for Logback
Branch: master
Clone or download

Build Status

Logback AWSLogs appender

An Amazon Web Services CloudWatch Logs appender for Logback.

Thank you for your help:

Quick start




The simplest config that actually (synchronously) send logs to CloudWatch (see More configurations section for a real life example):


    <appender name="AWS_LOGS" class="ca.pjer.logback.AwsLogsAppender"/>

        <appender-ref ref="AWS_LOGS"/>


With every possible defaults:

  • The Layout will default to EchoLayout.
  • The Log Group Name will default to AwsLogsAppender.
  • The Log Stream Name will default to a timestamp formated with yyyyMMdd'T'HHmmss.
  • The AWS Region will default to the AWS SDK default region (us-east-1) or the current instance region.
  • The maxFlushTimeMillis will default to 0, so appender is in synchronous mode.

AwsLogsAppender will search for AWS Credentials using the DefaultAWSCredentialsProviderChain.

The foud Credentials must have at least this Role Policy:

  "Statement": [
      "Action": [
      "Effect": "Allow",
      "Resource": "arn:aws:logs:*:*:*"


As usual with SLF4J:

// get a logger
org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(MyClass.class);

// log"HelloWorld");

More configurations

It may be worth quoting this from AWS, beacause this is why we need to have unique logStreamName:

When you have two processes attempting to perform the PutLogEvents API call to the same log stream, there is a chance that one will pass and one will fail because of the sequence token provided for that same log stream. Because of the sequencing of these events maintained in the log stream, you cannot have concurrently running processes pushing to the same log-stream.

A real life logback.xml would probably look like this (when all options are specified):

<configuration packagingData="true">

    <!-- Register the shutdown hook to allow logback to cleanly stop appenders -->
    <!-- this is strongly recommend when using AwsLogsAppender in async mode, -->
    <!-- to allow the queue to flush on exit -->
    <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>

    <!-- Timestamp used into the Log Stream Name -->
    <timestamp key="timestamp" datePattern="yyyyMMddHHmmssSSS"/>

    <!-- The actual AwsLogsAppender (asynchronous mode because of maxFlushTimeMillis > 0) -->
    <appender name="ASYNC_AWS_LOGS" class="ca.pjer.logback.AwsLogsAppender">
        <!-- Send only WARN and above -->
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <!-- Nice layout pattern -->
            <pattern>%d{yyyyMMdd'T'HHmmss} %thread %level %logger{15} %msg%n</pattern>
        <!-- Hardcoded Log Group Name -->
        <!-- Timestamped Log Stream Name -->
        <!-- Hardcoded AWS region -->
        <!-- So even when running inside an AWS instance in us-west-1, logs will go to us-west-2 -->
        <!-- Maximum number of events in each batch (50 is the default) -->
        <!-- will flush when the event queue has 50 elements, even if still in quiet time (see maxFlushTimeMillis) -->
        <!-- Maximum quiet time in millisecond (0 is the default) -->
        <!-- will flush when met, even if the batch size is not met (see maxBatchLogEvents) -->
        <!-- Maximum block time in millisecond (5000 is the default) -->
        <!-- when > 0: this is the maximum time the logging thread will wait for the logger, -->
        <!-- when == 0: the logging thread will never wait for the logger, discarding events while the queue is full -->

    <!-- A console output -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
            <pattern>%d{yyyyMMdd'T'HHmmss} %thread %level %logger{15} %msg%n</pattern>

    <!-- Root with a threshold to INFO and above -->
    <root level="INFO">
        <!-- Append to the console -->
        <appender-ref ref="STDOUT"/>
        <!-- Append also to the (async) AwsLogsAppender -->
        <appender-ref ref="ASYNC_AWS_LOGS"/>


See The logback manual - Chapter 3: Logback configuration for more config options.

You can’t perform that action at this time.