logging into one file problem

Maksim Kasimov maksim.kasimov at gmail.com
Mon Sep 5 11:26:50 EDT 2005


hello

in my modules, I'm using logging module, doing thus (there is a few modules):


in module1.py:
hdl = logging.StreamHandler()
fmt = logging.Formatter("%(name)s:\t%(levelname)s:\t%(asctime)s:\t%(message)s")
hdl.setFormatter(fmt)
log = logging.getLogger('module1')
log.addHandler(hdl)



In script, which is uses these modules, I'm doing in a similar way:


in script.py:
hdl = logging.StreamHandler()
fmt = logging.Formatter("%(name)s:\t%(levelname)s:\t%(asctime)s:\t%(message)s")
hdl.setFormatter(fmt)
log = logging.getLogger('script')
log.addHandler(hdl)



Than, to direct all output into one log-file I'm doing like this:

script.py >> script.log 2>&1


All works as expected - all output in one file (script.log), but only until syslog will rotate script.log, than output to log-file stops.

How to avoid this situation?

i can't using something like this:

hdl = logging.FileHandler('script.log')

because modules are used in other scripts, and log output of each application must be in different files.

and doing in script.py like this:

module.hdl = hdl
module.log = log

will works, but it is very inconvenient, because in main script, i'm not importing all the modules (some modules imported by other modules).


thanks for help.

Python 2.2.3
FreeBSD


-- 
Best regards,
Maksim Kasimov
mailto: maksim.kasimov at gmail.com



More information about the Python-list mailing list