Logrotate's rotation, timing, and may more are configurable. This section guides you on how to configure logrotate's timing and rotation.
The config file location is located at:
/etc/logrotate.conf
log-specific config files are located at:
/etc/logrotate.d/
To keep the naming consistent, the name of the file must match the name in the log location, such as:
/etc/logrotate.d/ufw --> /var/log/ufw.log
logrotate first facilitates the global settings inside /etc/logrotate.conf
. Then, it parses the specific settings from the specific configurations and then overwrites it. There are a few important keywords.
rotate the archive for X times.
create new empty log file after rotation.
create new empty log file after rotation.
time period for rotation.
option to compress the rotated log files.
rotate based on sizes. Can specify M (megabytes), G (gigabytes), and etc.
rotate based on log's timing / age.
email the rotated log to an email address before deleted.
email the rotated log to an email address before deleted.
To setup accordingly, here are some examples.
# see "man logrotate" for details
# rotate log files weekly
weekly
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
#dateext
# uncomment this if you want your log files compressed
#compress
# packages drop log rotation information into this directory
include /etc/logrotate.d
# system-specific logs may be also be configured here.
Specific file must wrap against the actual log file location.
/var/log/ufw.log
{
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
invoke-rc.d rsyslog rotate >/dev/null 2>&1 || true
endscript
}
That's all for configuring logrotate
.