Make a note before you forget it. I was making a sample to understand how logs are sent to CloudWatch Logs, but I couldn't find a reference site.
Now this.
https://github.com/kojiisd/cloudwatch-logs-java-standalone
cloudwatch-logback-appender https://github.com/j256/cloudwatch-logback-appender
If you edit the contents of logback.xml, you can freely flow the log to some extent.
<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
Orsecretkey
Seems to go to the awsconfig of the execution machine if the item itself is deleted (although I have not tried it)
The log was successfully output to CloudWatch Logs. (If the log group or log stream does not exist, it will be created)
Obviously, in order to send data to CloudWatch Logs in the library, we will do various initialization and data sending. Since that process is executed in a thread, when the logging process of the caller ends and the application ends, the child thread side also ends automatically, and the log is not sent to CloudWatch Logs. (Actually, I don't think it's possible to send logs with such a single application, so I don't think it's something to worry about) I noticed while looking at the source on the OSS side.
To avoid that, I intentionally put Sleep processing in the implementation for about 20 seconds.
It was very easy to achieve if I didn't get into the points of caution.
Recommended Posts