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
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • Unlocking the Benefits of a Private API in AWS API Gateway
  • Zero Trust for AWS NLBs: Why It Matters and How to Do It
  • Unlocking the Power of Serverless AI/ML on AWS: Expert Strategies for Scalable and Secure Applications
  • Context Search With AWS Bedrock, Cohere Model, and Spring AI

Trending

  • A Guide to Developing Large Language Models Part 1: Pretraining
  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • Optimize Deployment Pipelines for Speed, Security and Seamless Automation
  • Scaling Mobile App Performance: How We Cut Screen Load Time From 8s to 2s
  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.5K 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

  • Unlocking the Benefits of a Private API in AWS API Gateway
  • Zero Trust for AWS NLBs: Why It Matters and How to Do It
  • Unlocking the Power of Serverless AI/ML on AWS: Expert Strategies for Scalable and Secure Applications
  • Context Search With AWS Bedrock, Cohere Model, and Spring AI

Partner Resources

×

Comments
Oops! Something Went Wrong

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

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

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 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!