Getting logging under control?

I typed this off the top of my head without testing so proceed carefully and make backups!

Here’s a quick answer if it’s a unix system, make a script that does the following:

DATE=date +"%Y%m%d"
cp /PATH_TO_LOGS/production.log /PATH_TO_LOGS/production.log.$DATE
cp /dev/null /PATH_TO_LOGS/production.log
find /PATH_TO_LOGS -name “production.log." ! -name ".gz” -mtime +7 -exec gzip {} ;
find /PATH_TO_LOGS -name “production.log.*” -mtime +14 -exec rm {} ;

This will copy the log to a datestamped file (you can copy to another dir if you want). Then it will null out the current log. Then it will compress any datestamped log older then a week. Then it will remove any datestamped log older then 14 days.

You don’t have to remove it, you can move the file somewhere with more storage if you want with a line like this:

find /PATH_TO_LOGS -name “production.log.*” -mtime +14 -exec mv {} /PATH_TO_ARCHIVE ;

Put it in your crontab to run every night:

0 30 * * * /PATH_TO_SCRIPT/

Try not to do it right at midnight. Other things may be happening at that moment.