logging producing redundant entries

Jed Parsons jedp at ilm.com
Fri Mar 31 18:13:16 EST 2006



Thanks, Kent and Peter,

Definitely making progress here.  I've got propagate = 0, and am testing 
for handlers before doing any addHandler business.  (The handlers test 
seems to make the most difference.)

I'm down to two entries per time now!  And prodding Zope to reload the 
module doesn't cause the number to increase.

It's a good thing for Zope to reload modules when you touch them, but I 
didn't anticipate that this would be a side-effect.

Thanks again for your help.  Cheers,
j

Kent Johnson wrote:
> Jed Parsons wrote:
>> Thanks, Peter and alex23,
>>
>> The metalog test shows that the code is only being executed once at a time.
>>
>> And if I take those lines and put them in a shell script (fixing the 
>> FileHandler - sorry about the bad copy there), they work as expected, 
>> producing a single log entry.
>>
>> So I'm left with:
>>
>> - logging code that works properly in isolation in a shell script
>> - zope extension code that gets called only once (metalog test)
>> - logging code produces multiple entries when executed in extension
>> - logging code seems to produce more and more entries over time
>>
>> Am I somehow accumulating a growing list of loggers by having this code 
>> at the top of a zope Extension?  If I cause the extension to be 
>> re-evaluated, do I somehow attach another logger?  (I'm grasping at 
>> straws...)
> 
> It sounds like Zope is reloading your extension. Each time it is 
> reloaded you will attach another logger.
>> I've tried the following to only call getLogger once, but it doesn't 
>> seem to help:
>>
>> try:
>>      _logger
>> except NameError:
>>      _logger = logging.getLogger('login')
>>      etc...
> 
> No, that won't work if it really is a reload, _logger will never be 
> defined. Can you put the logging setup somewhere else, in a module that 
> is only loaded once? Or inspect _logger.handlers to see if it already 
> contains a FileHandler to your log file, and only add it if it is not 
> there already.
> 
> Kent

-- 
Jed Parsons       Industrial Light + Magic  (415) 746-2974
	
grep(do{for(ord){(!$_&&print"$s\n")||(($O+=(($_-1)%6+1)and
grep(vec($s,$O++,1)=1,1..int(($_-6*6-1)/6))))}},(split(//,
"++,++2-27,280,481=1-7.1++2,800+++2,8310/1+4131+1++2,80\0.  What!?")));



More information about the Python-list mailing list