Catalogue
Configuring logrotate to Append a Daily Date to Log File Names, Set Retention Period, and Compress Old Files

Configuring logrotate to Append a Daily Date to Log File Names, Set Retention Period, and Compress Old Files

🌐 日本語で読む

Overview

The default settings in /etc/logrotate.conf have the following inconveniences:

  • Log file names are given sequential numbers like error_log.1, which makes it hard to tell the actual date.
  • By default, logs are kept for only 4 weeks, so there is only about a month’s worth of information. In some cases you simply cannot go back far enough to investigate.
  • Files are not compressed, so they take up disk space.

These make investigation very inconvenient.

When httpd is installed via yum, the initial logrotate.conf settings look like this:

Append the date to log file names

Add the following line to /etc/logrotate.conf:

1
dateext

Set the log retention period to half a year (53/2 weeks ≒ 27)

1
2
# keep 4 weeks worth of backlogs
rotate 27
  • Since disk capacity may be a concern, please consider how large the logs will grow per month before deciding on these settings.

Date

Compress old files

1
2
# uncomment this if you want your log files compressed
compress

Rotating Apache logs by date

The day after applying the settings

You can see that the output looks like this:

1
2
error_log-20150315.gz
error_log

If full-width characters are present in logrotate.conf, rotation may not work correctly, so please be careful.

Configuring logrotate to Append a Daily Date to Log File Names, Set Retention Period, and Compress Old Files

https://kenzo0107.github.io/en/2015/03/17/logrotate-daily/

Author

Kenzo Tanaka

Posted on

2015-03-17

Licensed under