To avoid the logs growing too large logrotation can be configured with Linux's logrotate tool. The logrotation configuration file is located at: /etc/logrotate.d/your_app_name Example of logrotate configuration file for a Rails app (remember to remove the comments!):
# monitor the /home/deploy/path/to/my/app/shared/log/*.log file
/home/deploy/path/to/my/app/shared/log/*.log {
weekly # rotate weekly
missingok # avoids halting on any error and carries on with the next log file
rotate 52 # 52 days worth of logs would be kept
compress # compress using gzip
delaycompress # delays the compression process till the next log rotation
notifempty # avoid log rotation if the logfile is empty
copytruncate # makes a backup copy of the current log and then clears the log file for continued writing
# using copytruncate option avoids having to restart the rails app after every log rotation
}
To verify if a particular log is indeed rotating or not and to check the last date and time of its rotation, check the /var/lib/logrotate/status file.
cat /var/lib/logrotate/status
Log rotation can also be triggered manually with:
sudo logrotate -v /etc/logrotate.d/your_app_name
Sometimes you want to trigger log rotation even when logrotate thinks the log doesn't need rotation, you can do so by passing the -f option to "force" the rotation:
sudo logrotate -vf /etc/logrotate.d/your_app_name