1

I'm trying to figure out how to include the current date and the IP number of the current host inside the Apache log file names, but I fail how to see how I can do that. Part of that has to do with the fact that I don't understand the log rotation mechanism that seems to be enabled by default. Haven't been able to find any documentation on why I have access.1.log, access.xxx.gz.log files.

(I mean, I do understand that it is log rotation, but I don't see how I can influence it. I also understand I could pipe log output through some sort of command to include the current IP number in the file name, but I would assume I would lose my log rotation that way. Basically I want the current mechanism, but then include the IP number in the name, and a date rather than a number.)

3
  • 1
    I have been digging a little further now. It turns out that the different files with a number appended at the end are generated by some daily rotation scheme, but they are getting created when you restart the server. If you restart the server, the numbers of the existing files will be bumped by one, the current file will be written to access.2.gz.log and the new file will be written to access.1.log. Jan 13, 2012 at 13:06
  • 1
    Also in order to have real log rotation (based on a daily rotation scheme) you need to use the CustomLog directive and pipe the log file through rotatelogs (Apache), cronolog or vlogger. I don't know about the first case, but neither cronolog nor vlogger gzip files upon rotation. The FAQ of cronolog says you better use cron for that instead. Jan 13, 2012 at 13:10
  • 1
    It sounds like you are looking for two things: the logrotate manual and a solution for parsing your log files (there are many free analytics solutions which work for Apache)
    – danlefree
    Jan 17, 2012 at 14:19

1 Answer 1

2

This is how log rotation is handled on my Apache server.

LogFormat "%h %l %u %t \"%r\" %>s %b" common
CustomLog "|/usr/local/sbin/cronolog --american /usr/local/apache2/logs/access_log.%Y%m%d" common

Cronolog creates a daily log file named something like access_log.20120213. I then have a cron job set to move old logs into a subdirectory, gzip logs files older than a week and clean out anything older than one year.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.