Logrotate a custom log file

Logrotate is a system utility for managing and automatic rotating log files on system. In this post we will add a custom log file to rotate periodically.

Intro to Logrotate

Logrotate is installed on Ubuntu/Debian by default. Also, logrotate is available on many other Linux distributions as well, but the default configuration may be quite different.

First, let’s check Logrotate version on our system:

$ logrotate --version

Output:
logrotate 3.8.7

Logrotate’s configuration information can generally be found in two places

/etc/logrotate.conf

and

/etc/logrotate.d/

Adding a custom log to rotate

Add log file

touch /var/www/wartburg.science/log/error_log.log

To add some configuration to /etc/logrotate.d/

nano /etc/logrotate.d/wartburg-log

Appen following to config file:

/var/www/wartburg.science/log/error_log.log {
  daily
  rotate 7
  missingok
  rotate 14
  compress
  notifempty
  copytruncate
}

Testing

Testing configuration:

logrotate /etc/logrotate.conf --debug