[英]how to collect logs on AWS from dockerized spring boot?
In spring boot logs by default go to stdout. 在春季启动日志中,默认情况下转到stdout。 that's nice standard - less config, no directory configuration etc. but I want to build a docker image and run it on aws.
这是一个很好的标准-更少的配置,没有目录配置等,但是我想构建一个docker镜像并在aws上运行它。
how can i get all the logs from dockerized spring-boot stdout? 我如何从dockerized spring-boot stdout获取所有日志? does cloudwatch support it?
cloudwatch支持吗? is there a simple solution or do i have to switch to logging to a file, doing docker volumes mount etc?
有没有简单的解决方案,还是我必须切换到记录文件,进行docker卷安装等?
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.
您可以使用AWS Cloudwatch日志,并可以通过CloudWatch本身配置警报。 In order to use it, you can configure your slf4j backend.
为了使用它,您可以配置slf4j后端。
<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. 显然,这取决于您的体系结构:例如,如果您有filebeat,则可以将filebeat配置为使用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) 如果对ec2实例使用经ecs优化的AMI(至少应为1.9.0),则还可以对容器使用aws日志驱动程序:1.在启动ecs代理之前,必须更改/ etc / ecs / ecs .config并使用以下命令调整ECS_AVAILABLE_LOGGING_DRIVERS:
["json-file","awslogs"]
2.激活自动配置功能以为ecs任务创建日志组(您也可以手动创建组,但我想您希望在此进行更多自动化) )
For more informations about aws logdriver, you can look on aws documentation: 有关aws logdriver的更多信息,请查看aws文档:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.