Skip to content

Logs⚓︎

Using logrotate to reduce disk space usage from logs.

logrotate docs

Find your version of logrotate⚓︎

logrotate --version
message from terminal
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.

cat /etc/logrotate.conf

to modify file

sudo nano /etc/logrotate.conf

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.

# keep 4 weeks worth of backlogs
rotate 4
assigned ownership of logs to admin
# use the adm group by default, since this is the owning group
# of /var/log/syslog.
su root adm
assigned ownership of logs to admin
# 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

# create new (empty) log files after rotating old ones
create
remove the hashtag before dateext if you'd like the log files to display the date
# use date as a suffix of the rotated file
#dateext
it is recommended to compress files to save on space
# 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 also be configured here.

Logrotate for individual applications⚓︎

cd /etc/logrotate.d
list individual applications
ls -la
to view a specific logrotate for each application listed previously
cat nameofapplication

Logrotate for your own application⚓︎

This example is for ditto.

create a logrotate file for it, since it doesn't already have one
sudo nano /etc/logrotate.d/ditto

In the empty window that opens, include the following, and modify as you wish.

create a logrotate file for it, since it doesn't already have one
/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