DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 2
  • Compliance Automated Standard Solution (COMPASS), Part 11: Compliance as Code, the OSCAL MCP Server Way
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 1
  • AWS Managed Database Observability: Monitoring DynamoDB, ElastiCache, and Redshift Beyond CloudWatch

Trending

  • Beyond Conversation: Mastering Context with Claude Code Skills and Agents
  • Agentic AI Design Patterns and Principles: Building Autonomous, Collaborative Systems
  • Comparing Top Gen AI Frameworks for Java in 2026
  • How to Set Up and Run PostgreSQL Change Data Capture
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Logging to AWS Cloudwatch Logs

Logging to AWS Cloudwatch Logs

Learn how to easily configure the slf4j logging framework to use AWS Cloudwatch to store your logs, for AWS or on-premise.

By 
Dieter Bogdoll user avatar
Dieter Bogdoll
·
Mar. 13, 18 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
28.8K Views

Join the DZone community and get the full member experience.

Join For Free

In case you are already using slf4j as your logging framework, this article will show you how easy
it is to configure your logging to use AWS Cloudwatch for storing your logs.

This can be used for applications which are running on AWS or on-premise.

You can find the library on GitHub, which does it by using logback as the slf4j backend.

In the following steps, you can see a minimal configuration for an appender which assumes that the application is running on an EC2 instance with an IAM profile which the rights to
access Cloudwatch Logs:

<appender name="cloud-watch" class="io.github.dibog.AwsLogAppender">

    <createLogGroup>true</createLogGroup>
    <groupName>group-name</groupName>
    <streamName>stream-name</streamName>
    <dateFormat>yyyyMMdd_HHmm</dateFormat>

     <layout>
        <pattern>[%thread] %-5level %logger{35} - %msg %n</pattern>
     </layout>

</appender>
  • The tag <createLogGroup> indicates if the appender should create the log group if it does not
    exist. For that, you need to have the logs:CreateLogGroup and logs:DescribeLogGroups permissions.

  • <groupName> lets you specify the name of the log group.

  • <streamName> lets you either specify the name of the stream or its prefix.

  • <dateFormat> If you specify a date format, the actual stream name is built out of the above
    specified streamName concatenated with the string computed by the dateFormat.
    As soon as that name changes, the existing stream will be closed and a new one created.

  • In the <layout>, you can describe the format in which the log event should be displayed.

In case your application is not running on AWS or you don't want to use the IAM Profile of the
EC2 instance, you can also specify the AWS credentials; you need to have at least the permissionslogs:DescribeLogStreamsandcredentialslogs:PutLogEvents:

<appender name="cloud-watch" class="io.github.dibog.AwsLogAppender">

    <awsConfig>
        <credentials>
            <accessKeyId></accessKeyId>
            <secretAccessKey></secretAccessKey>
        </credentials>

        <region></region>

        <clientConfig class="com.amazonaws.ClientConfiguration">
            <proxyHost></proxyHost>
            <proxyPort></proxyPort>
        </clientConfig>
    </awsConfig>

    <createLogGroup>false</createLogGroup>
    <queueLength>100</queueLength>
    <groupName>group-name</groupName>
    <streamName>stream-name</streamName>
    <dateFormat>yyyyMMdd_HHmm</dateFormat>

     <layout>
        <pattern>[%thread] %-5level %logger{35} - %msg %n</pattern>
     </layout>

</appender>

Enter your accessKey and the secretAccess in the correct location. You also have to specify which
AWS Region should be used. The ClientConfiguration is only necessary if you have some proxy issues. Please refer to these docs for details.

AWS

Opinions expressed by DZone contributors are their own.

Related

  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 2
  • Compliance Automated Standard Solution (COMPASS), Part 11: Compliance as Code, the OSCAL MCP Server Way
  • Build a GitHub Slack Bot With AWS Bedrock and MCP, Part 1
  • AWS Managed Database Observability: Monitoring DynamoDB, ElastiCache, and Redshift Beyond CloudWatch

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook