Wish: Allow all log Handlers to accept the level argument

Peter Otten __peter__ at web.de
Thu May 24 07:13:43 EDT 2012


Jean-Michel Pichavant wrote:
> Peter Otten wrote:
>> Jean-Michel Pichavant wrote:
>>>>>>> Fayaz Yusuf Khan wrote:
>>>>>>> Jean-Michel Pichavant wrote:
>>>>>>>>>>>>> Meanwhile you can shorten the code this way:
>>>>>>>>>> root.addHandler(FileHandler('debug.log'))
>>>>> root.handlers[-1].setLevel(DEBUG)
>>>>>>>>>>>>>>>>>>> Eh? Readability was the aim.
>>>>>>>>>>> I fail to see how it's not readable, code is short and no magic is
>>> involved provided you know about slicing list items. Anyway, to answer
>>>>>>> You have to know or verify that .addHandler() appends to the .handlers
>> list, you have to check if or under which conditions
>>>> h = SomeHandler()
>> root.addHandler(h)
>> assert h is root.handlers[-1]
>>>> can fail. In short, if I see such a hack my trust in the author of that
>> code is significantly lowered.
>>>>> I now fail to see how it's a hack. handlers is a public attribute of
> loggers.

Can you come up with a setup that makes the above assertion fail? I can 
think of three: 
- adding a handler twice
- adding a singleton handler
- adding handlers from multiple threads
> FYI
>> def addHandler(self, hdlr):
> """
> Add the specified handler to this logger.
> """

Subject to change. I think in current Python
> if not (hdlr in self.handlers):
> self.handlers.append(hdlr)

is protected by a lock.


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /