Oct 21

Rotating Apache log files on Mac OS

Recently I went through setting up a new Mac from scratch instead of porting it from another machine. As part of this process I set up Apache with a bunch of log files for various VHost’s I’m working on for a side project I’m playing with. This means plenty of logs files. In the past I’ve generally not worried about doing anything with the log files, I just let them grow and if they got too big, nuked them by hand. However this time round I figured I’d get them rotated properly so that I could have clean logs each day that I’m working.

I did some quick searching and found that Mac OS uses newsyslog instead of logrotate which lead me to a post on Rotating Apache httpd logfiles on FreeBSD which covered pretty close to what I wanted. The example it had looked like this:

/var/log/httpd-access.log www:www 440 9 * $W1D4 J /var/run/httpd.pid 30
/var/log/httpd-error.log www:www 440 9 * $W1D4 J /var/run/httpd.pid 30

Now that sounds pretty close to what I want except I’ve got a bunch of these and I wanted to use a wildcard. Turns out that the solution was another quick Google away on ServerFault, a StackOverflow site with a single answer:

# logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
/path/logs/*.log    644  7     100  $D0   G

This looks like me, so I took that and merged it with the above config and created


that looks like this:

# logfilename          [owner:group]    mode count size when  flags [/pid_file] [sig_num]
/var/log/apache2/*_log                  640  10    *    $D0   JG    /var/run/httpd.pid 30

This seems to be rotating my log files, it should keep ten of them, it’ll do it daily, bzip2 compress them and also bounce Apache to get it writing to the new days file.

No comments

No Comments

Leave a comment

%d bloggers like this: