[issue876421] logging handlers raise exception on level

Mickey Killianey report at bugs.python.org
Tue Jul 13 11:01:51 CEST 2010


Mickey Killianey <mickey.killianey at gmail.com> 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 <report at bugs.python.org>
<http://bugs.python.org/issue876421>
_______________________________________


More information about the Python-bugs-list mailing list