I finally fixed my apache logging config. My apache has not logged anything since I installed debian on my server a while back. I suppose that for privacy, this is good news. However I enjoy statistics so I enjoy logging. Maybe eventually I’ll hash the logged IP addresses to keep the Man from getting them.
My old configuration required manual logging settings for all my virtual hosts, of which there are a number. However I recently stumbled upon a logging utility called vlogger which allows for quick and easy logging setup for your entire server, and it will split files by date or size, and place logs for different virtual hosts into separate folders. Which is exactly what I wanted.
The configuration was a breeze. Here is mine:
LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" vcombined
CustomLog "| /usr/sbin/vlogger -t %Y%m%d-access.log -s access.log /home/www/logs" vcombined
ErrorLog "| /usr/sbin/vlogger -t %Y%m%d-error.log -e -s error.log /home/www/logs"
Place these lines into apache2.conf or httpd.conf or into a new file in conf.d.
The first line creates a new log configuration called vcombined. I basically took the original combined configuration and added a %v at the beginning. This is important, because %v stands for the name of the virtual host, and vlogger uses this to place your log files into the folder with that name. You can actually place any value there if you wish to split your logs into some specific folders. This value is stripped from the end result (this can be disabled tho).
Then I simply told apache to send all log entries to vlogger.
-t %Y%m%d-access.log redefines the filename of the resulting logs, I like the ISO date standard so I changed it from the default. The default %m%d%Y-access.log which is good if you like the US date format.
-s access.log is the name of the “live” log file symlink, it can actually be pretty much anything you want.
-e is for error mode and should be used with the ErrorLog directive.
/home/www/logs is the parent directory into which you wish to place the log files and directories.
Note the vcombined at the end. If you simply place the default apache combined string, then your logs will be split into folders named after the IP addresses of your visitors and subsequently remove that IP address from the log. So remember the %v!
As always, read the docs if you are unsure.