Logrotate

From wikinotes

logrotate is a program to rotate/compress logs.

Documentation

github https://github.com/logrotate/logrotate

Tutorials

arch wiki https://wiki.archlinux.org/index.php/Logrotate

Locations

/etc/logrotate.conf config file

Install

pkg install logrotate  # FreeBSD
pacman -S logrotate    # Archlinux

Configuration

/var/log/messages {
    rotate 5
    weekly
    postrotate
        /usr/bin/killall -HUP syslogd
    endscript
}

"/var/log/httpd/access.log" /var/log/httpd/error.log {
    rotate 5
    mail recipient@example.org
    size 100k
    sharedscripts
    postrotate
        /usr/bin/killall -HUP httpd
    endscript
}

Some common options are:

hourly/daily/weekly/monthly  # rotate the log at this interval
create                       # create empty file on rotation
compress                     # compress old logs
rotate 5                     # keep 5x log rotations at once before deleting

Usage

# rotate all configured logs (by configured conditions)
logrotate /etc/logrotate.conf