简体   繁体   English

使用 AWS Elastic Beanstalk 进行应用程序日志记录

[英]Application logging with AWS Elastic Beanstalk

I have deployed a WAR to AWS Elastic Beanstalk on environment with Tomcat 8.5 with Java 8. The app loads and is working fine.我已经在 Tomcat 8.5 和 Java 8 的环境中将 WAR 部署到 AWS Elastic Beanstalk。应用程序加载并运行良好。 However, when I go to check the logs (Environment -> Logs -> Last 100 lines OR Full Logs) I do not see the logs written by the app.但是,当我 go 检查日志(环境 -> 日志 -> 最后 100 行或完整日志)时,我没有看到应用程序写入的日志。 There are some other logs like tomcat/activity/boot etc, but not the logs written by my application.还有一些其他日志,例如 tomcat/activity/boot 等,但不是我的应用程序编写的日志。 The logs work as expected when running locally, just not on AWS.日志在本地运行时按预期工作,而不是在 AWS 上。

Below is my logback.xml file:下面是我的 logback.xml 文件:

<configuration debug="true">
    <appender name="APPLOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>/var/log/my_app.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>/var/log/my_app_%d{yyyy-MM-dd}_%i.log</FileNamePattern>
            <maxHistory>7</maxHistory>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>5MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} %-5level %c{1} - %msg%n</pattern>
        </encoder>
    </appender>

    <root level="INFO">
        <appender-ref ref="LOGFILE" />
    </root>

</configuration>

In one of the Medium post I learned that we need to configure the EB environment so that the application's logs are included in the logs bundle.在一篇 Medium 帖子中,我了解到我们需要配置 EB 环境,以便应用程序的日志包含在日志包中。 So I put the following config file in the application's resources directory:所以我将以下配置文件放在应用程序的资源目录中:

files:
  "/opt/elasticbeanstalk/tasks/bundlelogs.d/applogs.conf" :
    mode: "000755"
    owner: root
    group: root
    content: |
      /var/log/*.log

  "/opt/elasticbeanstalk/tasks/taillogs.d/applogs.conf" :
    mode: "000755"
    owner: root
    group: root
    content: |
      /var/log/*.log

But that did not help, there was no change in the app's log behavior.但这并没有帮助,应用程序的日志行为没有变化。 This has been a frustrating ordeal so far, hoping for some help.到目前为止,这是一个令人沮丧的考验,希望能得到一些帮助。

I had faced similar issues with logging when I deployed my app to AWS.当我将应用程序部署到 AWS 时,我遇到了类似的日志记录问题。

A couple of things of note:有几点需要注意:

(1) The config file is correct (that's what I used), but that needs to go into an .ebextensions folder in your webapp directory: (1)配置文件是正确的(这就是我使用的),但是需要将 go 放入您的 webapp 目录中的.ebextensions文件夹中:

在此处输入图像描述

(2) You will need to change the location of your log file. (2) 您需要更改日志文件的位置。 Your app can't write to the var/log folder, but can write to the var/log/tomcat folder because of folder permissions issue.由于文件夹权限问题,您的应用无法写入 var/log 文件夹,但可以写入 var/log/tomcat 文件夹。

You can find more details on my question here: AWS Elastic Beanstalk Application Logging with Logback您可以在此处找到有关我的问题的更多详细信息: AWS Elastic Beanstalk Application Logging with Logback

Hope it works out for you!希望它对你有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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