Re: [PORTS] Logging (was Re: PostgreSQL 7.0-2 RPMset released.)

Palle Girgensohn <girgen@partitur.se>

From: Palle Girgensohn <girgen@partitur.se>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Lamar Owen <lamar.owen@wgcr.org>, Thomas Good <tomg@admin.nrnet.org>, pgsql-ports@postgreSQL.org, "PostgreSQL::General List" <pgsql-general@postgreSQL.org>, teg@redhat.com, Richard Smith <ozric@tampabay.rr.com>
Date: 2000-05-22T15:02:37Z
Lists: pgsql-hackers

Attachments

Tom Lane wrote:
> 
> Lamar Owen <lamar.owen@wgcr.org> writes:
> > The real problem with redirecting the postmaster output is the issue
> > of log rolling, which is impossible to do in the 'classic'
> > stderr/stdout redirect UNLESS you throw down postmaster when rolling
> > the log (unless you know a trick I don't).

I think I do ;-) read on...

> Yes.  I think ultimately we will have to do some logging support code of
> our own to make this work the way we want.  My thought at the moment is
> there's nothing wrong with logging to stderr, as long as there's some
> code somewhere that periodically closes stderr and reopens it to a new
> log file.  There needn't be a lot of code involved, we just need a
> well-thought-out spec for how it should work.  Comments anyone?
> 
>                         regards, tom lane

I really enjoy using apache's rotatelogs program. stderr is
redirected through a pipe to a very small and robust C program,
rotatelogs, that takes as arguments number of seconds between
log rotates and the log filename. Logs are rotated every
argv[2] seconds. The rotatelogs program takes care of closing
and reopening, and nothing has to done from the application,
just start postmaster with '2>&1 | rotatelogs ...' at the end,
and log to stderr.

Also, BSD license! :)

For reference, I enclose the program as an attachment; it's
less than 100 lines. Also, here's the man page:

Name
       rotatelogs - rotate Apache logs without having to kill
the
       server

Synopsis
       rotatelogs logfile rotationtime

Description
       rotatelogs is a simple program for use in conjunction
with
       Apache's  piped  logfile  feature  which  can be used
like
       this:

          TransferLog    "|rotatelogs   
/path/to/logs/access_log
       86400"

       This creates the files /path/to/logs/access_log.nnnn
where
       nnnn is the system time at which the log nominally 
starts
       (this time will always be a multiple of the rotation
time,
       so you can synchronize cron scripts with it).  At the 
end
       of  each  rotation time (here after 24 hours) a new log
is
       started.

Options
       logfile
              The path plus basename of the logfile.  The 
suffix
              .nnnn is automatically added.

       rotationtime
              The rotation time in seconds.

See Also
       httpd(8)