Java standalone app for sending logs to Amazon CloudWatch Logs with Slf4j/Logback

Koji Ishida
1 min readMar 17, 2019

--

Simple apps for sending logs to CloudWatch Logs with minimum edit.

Pre-condition

1. Don’t want to implement codes so much. → Use OSS on GitHub etc…
2. Minimum coding for work
3. Use Gradle

Result

Here is a result for implementation.
https://github.com/kojiisd/cloudwatch-logs-java-standalone

Use OSS

cloudwatch-logback-appender
https://github.com/j256/cloudwatch-logback-appender

Usage

Modifying logback.xml before starting, you can use logs to CloudWatch Logs.

<appender name="CLOUDWATCH" class="com.j256.cloudwatchlogbackappender.CloudWatchAppender">
<region>us-east-1</region>
<accessKeyId>XXXXXXX</accessKeyId>
<secretKey>XXXXXXX</secretKey>
<logGroup>test-loggroup</logGroup>
<logStream>test-logstream</logStream>
<layout>
<pattern>[%d{HH:mm:ss.SSS} [%thread] %-5level %logger{20} - %msg%n</pattern>
</layout>
<maxBatchSize>32</maxBatchSize>
</appender>

accessKeyId and secretKey can be deleted for using AWS configuration on your machine. (I didn’t try it)

Notice

To send logs to CloudWatch Logs, there are several processes in a library for initializing and data sending through the internet etc…

So for those processes, it will take a certain time. If you stop the application during processing, automatically the sending logs process will be stopped.

To avoid above situation (stopping after the application finished), in my sample application on GitHub, Sleep process exists for around 20 sec.

--

--

Koji Ishida
Koji Ishida

Written by Koji Ishida

Senior Solution Architect ofAcroquest Technology. CTO of Acroquest Myanmar Technology.

No responses yet