Logs⚓︎
Using logrotate to reduce disk space usage from logs.
Find your version of logrotate⚓︎
logrotate 3.19.0
Default mail command: /usr/bin/mail
Default compress command: /bin/gzip
Default uncompress command: /bin/gunzip
Default compress extension: .gz
Default state file path: /var/lib/logrotate/status
ACL support: yes
SELinux support: yes
Configuration⚓︎
To view file for the entire system. Later on we'll look at specific ones to individual applications.
to modify file
Ctrl + O to save
Ctrl + X to exit
Files can be rotated daily, weekly, monthly. Recommended is daily.
# see "man logrotate" for details
# global options do not affect preceding include directives
# rotate log files weekly
weekly
The number of default weeks is 4. If changed to daily, that would be 4 days. Monthly, 4 months. Adjust the number accordingly. In this case, logs more than a month old will be deleted.
# use the adm group by default, since this is the owning group
# of /var/log/syslog.
su root adm
# use the adm group by default, since this is the owning group
# of /var/log/syslog.
su root adm
The default in the next option is create, but copytruncate may be a better option to avoid issues.
source: Don't Let Logs FILL Your Server
# use date as a suffix of the rotated file
#dateext
# uncomment this if you want your log files compressed
compress
Logrotate for individual applications⚓︎
Logrotate for your own application⚓︎
This example is for ditto.
In the empty window that opens, include the following, and modify as you wish.
/var/log/dittooryourapp/*.log {
daily
missingok
rotate 14
compress
notifempty
create 0640 root adm
sharedscripts
postrotate
systemctl reload your-app
endscript
}
sources
video tutorial: Log Management
guide: A Complete Guide to Managing Log Files with Logrotate
guide: Hog To Manage Logfiles with Logrotate