Feature #1580

Rotating log file patch for mod_accesslog

Added by malyn 308 days ago. Updated 89 days ago.

Status:Wontfix Start:
Priority:Normal Due date:
Assigned to:- % Done:

0%

Category:mod_accesslog
Target version:1.4.20
Pending:

No

Resolution:

wontfix

Patch available:


Description

I patched mod_accesslog to support the automatic rotation of log files based on a strftime-style format string. This patch has been running on my custom build of lighttpd for a number of years now and has always worked well. This method of log rotation avoids the extra processes that would otherwise be required by a cronolog approach.

The patch adds the following boolean configuration item to lighttpd.conf:

  • accesslog.auto-rotate

If this value is set to true, then mod_accesslog will treat accesslog.filename as a strftime-style pattern for the purposes of opening (and creating) log files. For example, the following set of configuration options would create one log file for each month, with one directory for each year:


accesslog.auto-rotate = "enable" 
accesslog.filename = "/var/log/lighttpd/%Y/%Y%m.access.log" 

The following directory tree would eventually be created (assuming that lighttpd ran from November 2007 to March 2008):


/var/log/lighttpd/2007/200711.access.log
/var/log/lighttpd/2007/200712.access.log
/var/log/lighttpd/2008/200801.access.log
/var/log/lighttpd/2008/200802.access.log
/var/log/lighttpd/2008/200803.access.log

The patch will not check the filename pattern for a change more often than once a minute. In other words, you can rotate log files on a per-minute basis if you wish, but not on a per-second basis. The check happens each time a log file entry is about to be written, so the check could occur less frequently than once a minute if the server is not very busy.

The most recent version of this patch was based on lighttpd 1.4.15, although it appears to be compatible with 1.4.18 as well.

rotating_accesslog.patch (6.5 KB) malyn, 03/05/2008 04:18 AM

History

03/05/2008 03:22 PM - Anonymous

Nice feature - but isn't this a task for stuff like Logrotate? I can see requests such as compressing and other common log handling tasks arise. Personally, I don't think that lighttpd should handle those.

-- Lfe

03/06/2008 03:45 AM - malyn

I agree that lighttpd should not handle things like compression; I use a cron job to do that, for example. My goal with this patch was to make a minor (especially from a performance perspective) change to the mod_accesslog module that would get me 80% of what I wanted in a log rotation feature.

I am definitely not the right person to say if this feature should become a part of the official lighttpd distribution though. Mostly I just wanted to make the patch available to anyone else who wants the same 80%.

Thanks for the comments!

09/23/2008 05:14 PM - stbuehler

  • Status changed from New to Fixed
  • Resolution set to wontfix

As you need something to handle the logs anyway (like compressing, deleting old ones, ...) and logrotate already works, i think that should be enough for everyone.

10/10/2008 07:05 PM - stbuehler

  • Status changed from Fixed to Wontfix

Also available in: Atom PDF