简体   繁体   中英

how to collect logs on AWS from dockerized spring boot?

In spring boot logs by default go to stdout. that's nice standard - less config, no directory configuration etc. but I want to build a docker image and run it on aws.

how can i get all the logs from dockerized spring-boot stdout? does cloudwatch support it? is there a simple solution or do i have to switch to logging to a file, doing docker volumes mount etc?

It depends how your architecture looks like and what do you want to do with logs. Nowadays you can use a myriad of tools in order to read logs. You can use AWS Cloudwatch Logs and through this you can configure alertings through CloudWatch itself. In order to use it, you can configure your slf4j backend.

<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>

Obviously it depends from your architecture: if you have for example filebeat, you can configure filebeat to use cloudwatch.

If you use ecs-optimized AMI for the ec2 instances (it should be at least 1.9.0), you can also use the aws logdriver for your containers: 1. Before launch the ecs agent, you must change /etc/ecs/ecs.config and adjust ECS_AVAILABLE_LOGGING_DRIVERS with: ["json-file","awslogs"] 2. Activate the auto-configuration feature to create log group for ecs tasks (you can also create the groups manually, but I think you want here more automation)

For more informations about aws logdriver, you can look on aws documentation:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM