Using LogRotate

logrotate is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files. Each log file may be handled daily, weekly, monthly, or when it grows too large.

Main Config


It includes items from the directory include /etc/logrotate.d which is where your individual logconfig files will be stored.

Individual Config:

$ vi /etc/logrotate.d/rennetti

/var/www/vhosts/*.log /var/www/vhosts/*.log
    rotate 14 # only keep 14 days
    daily # rotate daily (or weekly, monthly, yearly)
    size 50M # rotate at 50M (or 100k, 100G)
    compress  # Gzip cmpression
    delaycompress # Don't copress until the next log is rotated
    sharedscripts # don't run postrotate until every log file is rotated 
        /usr/sbin/apachectl graceful > /dev/null

Command line

  • Verify it works: logrotate -d -d = debug and runs through the scripts but doesn't actually do anything

  • Run the script logrotate -f -v /etc/logrotate.d/rennetti -f = force and -v verbose

Log files


With Apache


Logrotate is not a daemon so it need sto run on cron: You will likely find it