log size handling

Matthew Seaman m.seaman at infracaninophile.co.uk
Thu Jul 17 14:11:13 UTC 2008


Mario Lobo wrote:
 
> What would be the proper way to set the rotation of apache logs in 
> newsyslog.conf when there are separate log files for each virtual host?
> 
> Do I have to rotate them myself via a script in crontab?

There are several ways to do this.  Here's three in addition to the
script that someone else just posted:

  * Use the 'G' option to newsyslog.  'G' says that the filename
    field of newsyslog.conf actually contains a shell globbing pattern
    (wildcard) and files matching that should be rotated and compressed.

  * Use the rotatelogs program that comes with Apache.  In this case,
    you replace the logging configuration statements in https.conf
    eg. instead of:

         CustomLog "/var/log/httpd-access.log" combine

    you have:

         CustomLog "|/usr/local/sbin/rotatelogs /var/log/httpd-access.log 86400"

    which will create a new log file every 86400 seconds (= 1 day) and
    label each one with the unix time it was created appended to the
    name. eg:

        /var/log/httpd-access.log.1216252800

    That will change files at midnight UTC each day, which is fine
    if your server lives in the UK but not quite as convenient if your
    server is in Australia.

  * Use the conceptually very similar program 'cronolog' (in ports as
    sysutils/cronolog) This works like 'rotatelogs' except that you give
    it a date-time pattern using the %-escapes as in strftime(3) -- so
    
        CustomLog "|/usr/local/sbin/cronolog /var/log/%Y/%m/%d/httpd-access.log"

    will create /var/log/2008/07/17/httpd-access.log  for today's
    traffic.  Timestamps are based on the TZ setting the server uses
    I believe, so would likely be the same as local wall-clock time.

With the last two, there's no facility to compress or delete old log
files: however it is pretty simple to write a very small shell script to
do either of those things.  The last two have the subtle advantage that
you don't need to signal apache at file rotation time, which means there
is absolutely no effect on performance when it switches to a new log file.  
You could switch log files every hour on a really busy site and not
notice the overhead.

	Cheers,

	Matthew

-- 
Dr Matthew J Seaman MA, D.Phil.                   7 Priory Courtyard
                                                  Flat 3
PGP: http://www.infracaninophile.co.uk/pgpkey     Ramsgate
                                                  Kent, CT11 9PW

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 258 bytes
Desc: OpenPGP digital signature
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20080717/fd581efa/signature.pgp


More information about the freebsd-questions mailing list