line duplication using logging to file

Vinay Sajip vinay_sajip at yahoo.co.uk
Tue Jan 9 05:07:39 EST 2007


seb wrote:

> Hi, I am writing to a file some basic information using the logging
> module.  It is working but in the log file some line are printed
> several time. I had put some print debugging messages in the logging
> function (so they appear on the consile) and they are called once only.
> Obviously there is some understantding of the logging module that I am
> missing.
>
> My simple logging program (see below) is called by several processes.
> In this way I can collect the information from various sources (and not
> use the network enabled logging module)
>
> I am using python 2.4 on WinXP SP2.
>
> Do you have any idea ? Thanks in advance.
>

I copied your two scripts into "appel_main.py" and "appel_log.py" and
when I run, I get a single line in main_log.txt:

2007-01-09 10:01:42,766 -  INFO -C:\temp\appel_main.py___?something

On the console is printed:

time.asctime() Tue Jan 09 10:04:25 2007 received level= info message=
C:\temp\appel_main.py___?something
logger info
_________ C:\temp\appel_main.py___?something

I didn't see any repetitions. Perhaps it's to do with multiple
processes in your environment?

If you call write_log several times you will add a handler several
times - this is not a normal pattern of use. You should separate setup
of Loggers/Handlers/Formatters from actually logging events via
debug(), info() etc.

Best regards,

Vinay Sajip




More information about the Python-list mailing list