A continuous growing log file in /data/web/public/var/log will reduce speed of your shop, so it’s important to avoid a log file that is bigger than a few MB’s.
To make sure the log files don’t grow exhaustively, we can use Logrotate, the Linux utility that rotates logfiles.
Configuring log rotate
To make use of Logrotate, first create a config file
# Rotate logs for production
# Rotate daily
# Rotate when the size is bigger than 59MB
# Compress old log files
# Always keep 4 weeks of log files
# Create a new log file with mode 0600
# Don't rotate file if not found
# Don't rotate log if file is empty
# Rotate logs for staging
Now test if your config file is working:
logrotate -v /data/web/logrotate.conf --state /data/web/.logrot_state ; echo $?
If the returned exit code on the end of the output is 0, all is well and we’re ready to configure a cronjob that triggers Logrotate.
Running logrotate periodically
When Logrotate is working, we’ll have to make sure it is run nightly to make sure all log files are rotated frequently.
To do this add the following cron to your crontab:
30 * * * * /usr/sbin/logrotate /data/web/logrotate.conf --state /data/web/.logrot_state
Now every hour the Logrotate cronjob will verify your log files and rotate when they’re getting bigger then 50MB or when the day is over.
Additional info can be found using the man command:
Or in this howto with some great additional examples.