Wish: Allow all log Handlers to accept the level argument

Jean-Michel Pichavant jeanmichel at sequans.com
Tue May 22 09:31:52 EDT 2012


Fayaz Yusuf Khan wrote:
> ***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)
>
> Python 2.7
> --
> Cloud architect, Dexetra SS, Kochi, India
> fayaz.yusuf.khan_AT_gmail_DOT_com, fayaz_AT_dexetra_DOT_com
> +91-9746-830-823
>
>
>   
Meanwhile you can shorten the code this way:

root.addHandler(FileHandler('debug.log'))
root.handlers[-1].setLevel(DEBUG)

JM




More information about the Python-list mailing list