logrotate is a system utility used in Unix-like operating systems to manage the automatic rotation, compression, removal, and mailing of log files. Each log file treated by logrotate is configured in a configuration file, typically located at /etc/logrotate.conf
or within /etc/logrotate.d/
for individual service configurations.
logrotate was originally developed to address the issue of log files growing indefinitely, which could consume disk space and make log analysis cumbersome. It has been part of many Linux distributions for decades, with its inception dating back to the early days of Linux:
logrotate performs several key functions:
The configuration for logrotate is done through plain text files, which define how and when log files should be rotated:
/etc/logrotate.conf
- Global settings for log rotation./etc/logrotate.d/
- Directory containing configuration snippets for individual services or applications.Configuration directives include:
weekly
, monthly
, daily
- Frequency of rotation.rotate
- Number of rotations to keep before deletion.compress
, delaycompress
- Whether to compress logs and when.create
- Specifies permissions, owner, and group for the new log file.postrotate
, prerotate
- Scripts to execute before or after rotation.Typically, logrotate is invoked by cron at regular intervals, as defined in the crontab:
0 0 * * * /usr/sbin/logrotate /etc/logrotate.conf