Vita Bourn
Vita Bourn

Reputation: 5

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. 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. There are some other logs like tomcat/activity/boot etc, but not the logs written by my application. The logs work as expected when running locally, just not on AWS.

Below is my logback.xml file:

<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. 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.

Upvotes: 0

Views: 1813

Answers (1)

Tony Scott
Tony Scott

Reputation: 205

I had faced similar issues with logging when I deployed my app to 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:

enter image description here

(2) You will need to change the location of your log file. Your app can't write to the var/log folder, but can write to the var/log/tomcat folder because of folder permissions issue.

You can find more details on my question here: AWS Elastic Beanstalk Application Logging with Logback

Hope it works out for you!

Upvotes: 2

Related Questions