Reducing log rotation frequency for AWS EC2

2019-07-15 13:58发布

问题:

I have a java app running on elastic beanstalk, with the log rotation to S3 set up and working fine. However, I find that my catalina.out log file only exists for up to 15 minutes before rolling to a new file, which makes debugging problems on the same day more tedious (get gz from s3 and unzip, instead of just ssh-ing and reading the log file).

Is there any way to configure this through tomcat/log4j or the elastic-beanstalk console? I believe it's an AWS thing, because we had the same app deployed on Dotcloud and it kept a single log file per day.

回答1:

As of Today, not really. The only thing that you can do is modify the file /etc/logrotate.conf.elasticbeanstalk in the EC2 instance where your app is running.

Change the size of the log and that should put more log info in one file:

/var/log/tomcat6/catalina.out /var/log/tomcat6/monitor_catalina.log /var/log/tomcat6/tail_catalina.log {
    size 20M <-- change to the file size that you want
    missingok
    rotate 2
    compress
    notifempty
    copytruncate
    dateext
    dateformat -%s
    lastaction
        /bin/chown tomcat:elasticbeanstalk /var/log/tomcat6/*gz; /bin/chmod 664 /var/log/tomcat6/*gz
    endscript
}

There's another post that has more info here:

Rotating S3 Logging using log4j with Elastic Beanstalk