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

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

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

Related

  • How to Use AWS Aurora Database for a Retail Point of Sale (POS) Transaction System
  • Optimizing Serverless Computing with AWS Lambda Layers and CloudFormation
  • Driving DevOps With Smart, Scalable Testing
  • Building Reliable LLM-Powered Microservices With Kubernetes on AWS

Trending

  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  • System Coexistence: Bridging Legacy and Modern Architecture
  • How to Convert XLS to XLSX in Java
  • After 9 Years, Microsoft Fulfills This Windows Feature Request
  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

  • How to Use AWS Aurora Database for a Retail Point of Sale (POS) Transaction System
  • Optimizing Serverless Computing with AWS Lambda Layers and CloudFormation
  • Driving DevOps With Smart, Scalable Testing
  • Building Reliable LLM-Powered Microservices With Kubernetes on AWS

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!