Wish: Allow all log Handlers to accept the level argument
Cameron Simpson
cs at zip.com.au
Thu May 24 18:53:14 EDT 2012
On 24May2012 12:48, Jean-Michel Pichavant <jeanmichel at sequans.com> 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.
|
| FYI
|
| def addHandler(self, hdlr):
| """
| Add the specified handler to this logger.
| """
| if not (hdlr in self.handlers):
| self.handlers.append(hdlr)
Nothing there says handlers is a list. (Nothing in the docs says that the
.handlers even exists, AFAICS.) Might be a set or something more esoteric.
Particularly, if I wanted to add and remove handlers a lot I might well
expect (or at least imagine) it to be a set.
So I too find:
root.handlers[-1]
a risky thing to say, and harder to read because it assumes something I
would not want to rely on. Versus the original proposal that avoids all
need to know how logging tracks its handler internally.
Cheers,
--
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
The reason that God was able to create the world in seven days is that he
didn't have to worry about the installed base. - Enzo Torresi
More information about the Python-list
mailing list