[Tutor] python logging module: two handlers writing to the same file - okay?

Hans Fangohr h.fangohr at soton.ac.uk
Mon Dec 17 12:31:31 CET 2007


HI Riccardo,

>>>
>>> As far as I can see, the only reason in your example program to  
>>> open the
>>> same file twice is to use two different formatters (i.e. two  
>>> different
>>> type of lines) in the same log,
>> Absolutely right.
>>
>>> if you'd drop the requirement for two
>>> different format of line in the same log (which is itself somewhat
>>> questionable) then you could use the same handler for both  
>>> loggers, thus
>>> opening only one file.
>>
>> True.
>>
>> FYI: The reason for wanting to use two different file formats is  
>> this:
>> we have a somewhat larger project (http://nmag.soton.ac.uk) where we
>> combine high-level Python code with low-level Objective Caml code  
>> (and
>> a number of libraries). We would like to use the Python-logging  
>> module
>> to log all sorts of messages coming from various parts of the  
>> code. In
>> particular, we find having the line number (and function name if the
>> python version provides this) useful information in the log messages
>> (which can bedone for Python code issueing log messages). However,
>> this information cannot be obtained from the OCaml code; thus we do
>> not want to waste space in the log messages, and therefore we'd like
>> to use different formatters.
>>
>> I'll reply to Ken's email in a minute, and I think that closes my  
>> query.
>>
>> Best wishes,
>>
>> Hans
>>
>
> One last thing Hans. If you are concerned about the space the log  
> files
> will use maybe it would be interesting to check out the zlib module
> which could be used to compress your log strings before sending  
> them to
> the logging module, then a utility to read the modules would close the
> cycle (caveat: I've never done this, just a crazy idea, but... what if
> it works?).

Apologies, I wasn't clear: just wanted to be nice to the user and  
avoid getting "(unknown)" entries in the log messages for the line  
number and the function name which pushes the useful message further  
to the right.

If we are talking compression, I guess you could inherit from the  
RotatingFileHandler and modify such that you gzip the rotated log files.

> Best of luck.
>
Many thanks,

Hans






More information about the Tutor mailing list