I have a daemon in Scala running on EC2 that processes jobs. For each job I know a (possibly) different log stream I'd like to append messages to.
How can I make a log-stream specific Appender that I can attach to my log4j logger, and change it when my listener moves on to the next job?
As you probably already know,Cloud-watch helps to record the logs of all aws services. Cloud-watch Log streams helps to listen the event automatically without any triggers. Using this Cloudwatch Log streams we can able to edit the cloud-watch logs.
To send action output to CloudWatch Logs (console)Open the AWS Systems Manager console at https://console.aws.amazon.com/systems-manager/ . In the navigation pane, choose Automation. Choose the Preferences tab, and then choose Edit. Select the check box next to Send output to CloudWatch Logs.
Open the CloudWatch console at https://console.aws.amazon.com/cloudwatch/ . In the navigation pane, choose Log groups. For Log Groups, choose the log group to view the streams. In the list of log groups, choose the name of the log group that you want to view.
Log4j Cloudwatch Appender is a simple to use Log4j Appender that allows you to stream your application logs directly into your AWS Cloudwatch Logs. In order to optimise network usage and mitigate throttling issues with AWS Cloudwatch, the actual sending of logs may be deferred.
This type of integration is blended of different things like AWS Java API, Log4J API, and AWS Cloud Watch configurations.
You can achieve that by implementing a customized log4j appender. An example you may leverage from github is the following link.
The idea is to add the log4j appender class to your source project and use it with your log4j library. The appender will use AWS CloudWatch API to append the logs for a specific log stream and log group that you need to create on AWS account.
Example: CloudwatchAppender.java
Every log your program creates will send a cloud watch event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With