我在 aws ec2 上运行了 Spring MVC 应用程序。现在我决定转移到 aws elastic beanstalk 并在迁移当前应用程序之前探索它。我几乎没有关于持久存储和应用程序日志记录的问题。
我的问题可能很幼稚,但请多多包涵:)
我正在使用 log4j 进行应用程序日志记录。 Log4j 将日志附加到硬盘上的指定位置。由于弹性 beanstalk 没有持久存储(一旦实例终止,存储将被删除)并且实例可能会根据负载规则增长/收缩。
所以我卡在了下面
- 我将如何配置 log4j 以附加日志。
- 如果我坚持使用当前的 log4j 实现,我将如何确保在启动实例时创建目录结构(我假设应用程序中没有代码更改)
- 如果我使用 log4j 中的 socketappender 那么我将如何区分来自不同实例的文件。
我一直在浏览描述 .ebextensions 目录使用的文章。我尝试使用 AWS 提供的基本 .conf 文件将日志拖到 S3,但我的应用程序日志没有成功。
在 .ebextensions 下创建应用程序目录的示例脚本
commands:
01_create_dir:
test: test ! -d "${DIR}"
command: mkdir "${DIR}"
引用链接:
- https://aws.amazon.com/blogs/aws/cloudwatch-log-service/
- http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/ebextensions.html
- http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environment-configuration-methods-during.html#configuration-options-during-console-ebextensions
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/