It’s probably installed by default but if not most distribution’s package managers refer to it as logrotate so installing it is pretty straight forward
apt install logrotate
dnf install logrotate
pacman -S logrotate
The main configuration file is:
/etc/logrotate.conf
With (by default) additional configuration files being loaded from the directory:
/etc/logrotate.d
Command to debug configuration file
logrotate -d "{:PathToConfigFile:}"
Command to force run configuration file in verbose mode
logrotate -vf "{:PathToConfigFile:}"
The following is an example configuration for rotating one log file:
/var/log/{:AppName:}.log {
missingok
compress
notifempty
copytruncate
}
The following is an example configuration for rotating logs file using a wildcard:
/var/log/{:AppName:}/* {
rotate 30
daily
missingok
olddir "/var/log/{:AppName:}/archive"
dateext
compress
}
Common configuration options
Option | Description |
---|---|
rotate {:NumberToKeep:} | Keep {:NumberToKeep:} amount of rotated logs |
daily / weekly / monthly | Rotate logs regularly |
size {:Size:} | Rotate logs when they hit {:Size:} in bytes. Can be set as (kilo/mega/giga)bytes with k/M/G |
missingok | Do not error if log file doesn’t exist |
olddir “{:DirectoryPath:}” | Places rotated logs into {:DirectoryPath:} |
dateext | Use date extension in YYYYMMDD format (e.g: 20380120) instead of number format |
notifempty | Do not rotate if log is empty |
compress /nocompress | Compress or not do compress rotated log files |
delaycompress | When using compress will delay compression of the log being rotated until the following rotation |
copytruncate | Do not delete existing log file, copy file for rotation and truncate contents of existing file |
create {:Mode:} {:Owner:} {:Group:} | Specify the permissions octal, owner and group when creating a new log file |
createolddir {:Mode:} {:Owner:} {:Group:} | Create the old directory if it does not exist and set the permissions octal, owner and group to those specified |