Configuring Log Rotation of Apache2 and Other Logs

and I noticed that they were being automatically rotated (access.log, access.log.1, etc.) and compressed with gzip (access.log.2.gz, etc.). This seems to be the default Ubuntu configuration. I wanted to make find out more, and I found this helpful article about Ubuntu logs, including Apache2 Log info and some basic log rotation info.

After reading through the info, I decided that I wanted to make a few changes. The log rotation happens via the brilliantly named logrotate command. It turns out that logrotate settings kept in 2 places.

Default logrotate settings

First, there are the default settings in /etc/logrotate.conf. You can view them with this command:

This handles the default settings. However, some applications set their own logrotate configuration. Look in /etc/logrotate.d to see the which applications override the default settings:

ls /etc/logrotate.d/

On my system, I wanted to make similar changes to the apache2 and mysql-server logs. Some of the changes were already there (eg: delaycompress directive) and others I had to add (eg: dateext directive).