简体   繁体   English

如何从dockerized spring boot上收集AWS上的日志?

[英]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.

相关问题 如何配置 AWS cloudWatchAgent 以递归方式从 EC2 实例上的文件夹收集日志? - How to configure AWS cloudWatchAgent to collect logs recursively from a folder on an EC2 instance? 如何从基于云的服务中收集日志? - How to collect logs from cloud based services? AWS Fargate 无法通过负载均衡器/公共 IP 访问 dockerized spring 启动应用程序 - AWS Fargate cannot access dockerized spring boot application over Load balancer/ public IP 启用 spring boot 应用程序日志并在 aws cloud watch 中观看 - Enabling spring boot application logs and watch it in aws cloud watch 如何在我的Spring Boot应用程序中从AWS访问环境变量 - How to access Environment Variable from AWS in my spring boot application 如何从 AWS AppConfig 设置 Spring 引导数据源 URL? - How to set up Spring Boot datasource URL from AWS AppConfig? 使用AWS CloudTrail收集应用程序日志 - Use aws cloudtrail to collect application logs 从Elastic Beanstalk获取正确的日志(Spring Boot) - Getting proper logs from Elastic Beanstalk (Spring Boot) 如何运行部署在 AWS 上的 Spring Boot 程序 - How to run a Spring Boot program deployed on AWS 如何在 AWS 中部署 Spring Boot 微服务 - How to deploy spring boot microservices in AWS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM