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.
FYI
def addHandler(self, hdlr):
"""
Add the specified handler to this logger.
"""
if not (hdlr in self.handlers):
self.handlers.append(hdlr)
Cheers,
JM
--
http://mail.python.org/mailman/listinfo/python-list