java - 弹性 beanstalk 的应用程序日志记录

标签 java amazon-web-services logging amazon-elastic-beanstalk

我在 aws ec2 上运行了 Spring MVC 应用程序。现在我决定转移到 aws elastic beanstalk 并在迁移当前应用程序之前探索它。我几乎没有关于持久存储和应用程序日志记录的问题。

我的问题可能很幼稚,但请多多包涵:)

我正在使用 log4j 进行应用程序日志记录。 Log4j 将日志附加到硬盘上的指定位置。由于弹性 beanstalk 没有持久存储(一旦实例终止,存储将被删除)并且实例可能会根据负载规则增长/收缩。

所以我卡在了下面

  1. 我将如何配置 log4j 以附加日志。
  2. 如果我坚持使用当前的 log4j 实现,我将如何确保在启动实例时创建目录结构(我假设应用程序中没有代码更改)
  3. 如果我使用 log4j 中的 socketappender 那么我将如何区分来自不同实例的文件。

我一直在浏览描述 .ebextensions 目录使用的文章。我尝试使用 AWS 提供的基本 .conf 文件将日志拖到 S3,但我的应用程序日志没有成功。

.ebextensions 下创建应用程序目录的示例脚本

commands:
  01_create_dir:
    test: test ! -d "${DIR}"
    command: mkdir "${DIR}"

引用链接:

EBS 控制台显示 URL 访问的 apache 日志。

我想知道有没有AWS提供的现成的解决方案,我没有找到。

最佳答案

来自 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-platform.html :

Standard output and error streams from processes started with a Procfile are captured in log files named after the process and stored in /var/log. For example, the web process in the preceding example generates logs named web-1.log and web-1.error.log for stdout and stderr, respectively.

基于此,您所要做的就是确保 log4j/logback 将您想要的日志输出到标准输出,即 CONSOLE。对于 Spring Boot,这是默认行为。

关于java - 弹性 beanstalk 的应用程序日志记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38848420/

相关文章:

java - HttpURLConnection 无效的 HTTP 方法 : PATCH

amazon-web-services - 有没有一种方法可以从 CloudFormation 在一个 Amazon RDS 数据库实例中创建多个数据库

amazon-web-services - AWS 无服务器框架 : MalformedPolicyDocument Error while creating IAM Role and Policy

java - 使用 slf4j 和 log4j 进行 Hibernate 日志记录不生成日志文件

java - 将 ImmutableList 转换为 List

java - android - 列表无法解析或不是字段

java - 哪些Java库可用于基本图像处理?

java - 从 S3 上的前几 MB 中提取视频元数据

spring-mvc - 即使配置了 log4j.xml,也无法启用 spring orm/事务日志记录

java - log4j2-gelf "ERROR StatusLogger appenders contains an invalid element or attribute "GELF""