[Tutor] redirecting output to logfile and logrotate

Winfried Tilanus winfried at tilanus.com
Fri Jul 22 10:14:02 CEST 2005


I am installing a server-like python program that opens a logfile in
the following way:

    # redirect output for logging to file
    applog = open(config.log, 'a', 1)
    sys.stdout = applog
    sys.stderr = sys.stdout

Througout the program are lines like:

            print '[', time.asctime(),']', message[:3]

The logfiles of the program can grow quite a big, so I decided to
include them in logrotate. That is where the problem started: everytime
the logfile gets rotated python loses track of it and stops logging.
The program is running on a linux server with python 2.2.

How can I make the logging (including stderr) 'logrotate-proof'?

Best wishes,


More information about the Tutor mailing list