I am having trouble with logging application logs with Elastic Beanstalk. I am running an spring mvc (NOT springboot) WAR file on AWS Elastic Beanstalk on a 'Tomcat 8.5 with Corretto 11 running on 64bit Amazon Linux 2/4.1.3' environment.
Previously I thought the problem was that I was unable to retrieve logs that were written by the application. However, after following suggestion in this question (AWS Elastic Beanstalk Application Logging with Logback) I was able to determine that there was no issue viewing the logs - the actual problem is that the logs are not even written. I ssh to the instance and the log file was not created in the /var/log directory
For reference, here is my logback file appender (full logback.xml in the linked question):
<appender name="APPLOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/var/log/java.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>/var/log/java_%d{yyyy-MM-dd}_%i.log</FileNamePattern>
<!-- keep 14 days' worth of history -->
<maxHistory>14</maxHistory>
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
<!-- or whenever the File size reaches 10MB -->
<maxFileSize>10MB</maxFileSize>
</timeBasedFileNamingAndTriggeringPolicy>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd'T'HH:mm:ss.SSSZ} [%thread][%X{remoteHost}] %-5level %c{1} - %msg%n</pattern>
<!-- <pattern>%d %-5p %c{1} - %m%n</pattern> -->
</encoder>
</appender>
The app is using slf4j-api-1.7.6, logback-classic-1.2.3 and logback-core-1.2.3. The application logs works as expected when loading the same war on Tomcat server locally.
So now I am wondering (1) Does logback work with Elastic Beanstalk? (2) If yes, does it require something special (permissions?, other dependencies) to write logs to the /var/logs
directory?
Based on the comments.
The issue was caused by permissions. By default user applications on EB do not have access to /var/logs
.
The solution was to modify the permissions so that the logs can be placed in /var/log/tomcat
.