[issue876421] logging handlers raise exception on level

2010-07-07 Thread Mickey Killianey

Mickey Killianey  added the comment:

Would you be willing to consider supporting the level keyword as a convenience 
for the most simple/common Handlers?  (For example, maybe just StreamHandler 
and FileHandler?)

--
nosy: +Mickey.Killianey

___
Python tracker 
<http://bugs.python.org/issue876421>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue876421] logging handlers raise exception on level

2010-07-13 Thread Mickey Killianey

Mickey Killianey  added the comment:

Vinay:  thanks for the response.

My use case is that I've inherited a legacy application with a problematic 
third-party module (call it 'foo').  I want to sprinkle in some file-logging 
for the 'foo' logger to trace what's going on, while making the minimal impact 
on the module.  Since 'foo' does some reflection on itself, I also want to 
avoid introducing new symbols in the module, if possible.

You said:

> If you're after convenience, you could use the dictionary 
> configuration API which allows you to set the levels 
> declaratively.

If by "dictionary configuration API" you're suggesting 
logging.config.dictConfig, then yes, it does meet my criteria, although the 
minimal amount of code to configure one file handler looks pretty long-winded 
for what seems like a fairly common request:

  logging.config.dictConfig({
  'version' : 1,
  'handlers' : {
'handler_name' : { 
  'class' : 'logging.FileHandler',
  'level' : logging.DEBUG,
  'filename' : 'foo.log',
},
  },
  'loggers' : {
'foo' : {
  'handlers' : [
'handler_name',
  ],
},
  },
})

Or were you suggesting logging.basicConfig?  The limitation of basicConfig 
seems to be that it only works on an unconfigured root logger, not on a named 
logger, and it doesn't work if anyone else has touched root.

I was hoping for something that's simple, easy-to-remember, easy-to-type, and 
makes a minimal impact on the module I'm debugging.  For example, how do any of 
these sound...?

...if basicConfig had an optional 'name' argument, so that it could config 
loggers other than root logger:

  logging.basicConfig(name='foo', filename='foo.log', level=DEBUG)

...if 'basicConfig' was a method on Logger:

  logging.getLogger('foo').basicConfig(filename='foo.log', level=DEBUG)

...if the handlers' setters supported the builder pattern and returned self 
from setLevel:

  logging.getLogger('foo').addHandler(FileHandler('foo.log').setLevel(DEBUG))


(Instead of commenting on this closed bug, should I enter this as a new issue 
and set it as a feature request?)

--

___
Python tracker 
<http://bugs.python.org/issue876421>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com