Fayaz Yusuf Khan <fayaz.yusuf.khan <at> gmail.com> writes: > > ***TRIVIAL ISSUE***, but this has been irking me for a while now. > The main logging.Handler class' __init__ accepts a level argument while none > of its children do. The poor minions seem to be stuck with the setLevel > method which considerably lengthens the code. > > In short: > Let's do this: > root.addHandler(FileHandler('debug.log', level=DEBUG) > Instead of this: > debug_file_handler = FileHandler('debug.log') > debug_file_handler.setLevel(DEBUG) > root.addHandler(debug_file_handler)
Levels on handlers are generally not needed (though of course they are sometimes needed) - level filtering should be applied at the logger first, and at the handler only when necessary. I don't especially want to encourage the pattern you suggest, because it isn't needed much of the time. The code above won't do any more or less than if you hadn't bothered to set the level on the handler. Don't forget, more complex configurations are effected even more simply using dictConfig(). Regards, Vinay Sajip -- http://mail.python.org/mailman/listinfo/python-list