[issue876421] logging handlers raise exception on level
Vinay Sajip
report at bugs.python.org
Tue Jul 13 16:54:44 CEST 2010
Vinay Sajip <vinay_sajip at yahoo.co.uk> added the comment:
----- Original Message ----
> Mickey Killianey <mickey.killianey at gmail.com> added the comment:
>
> 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.
True, but if you use basicConfig to configure the root logger, descendant
loggers (such as 'foo') will use those handlers. Of course, if someone else has
configured a handler for the root logger already, then you may not be able to
use this.
>
> 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?)
>
I'd like to avoid making the kinds of changes which are stylistic in nature; the
existing APIs will need to remain for backward compatiblity reasons, and I don't
want to add the same functionality using different idioms based on what are
essentially stylistic preferences. Also, remember that Python 2.x is essentially
frozen in terms of new releases (as 2.7 has been released and no 2.8 is planned)
so any API changes would apply to 3.2 and later only - I'm guessing you're still
on Python 2.x if you're using a legacy application.
When all's said and done, to configure a logger for 'foo' with a FileHandler and
a specific level will not require more than a few lines of code, so I'd just go
ahead and code them up and not worry about trying to get the whole thing to fit
on a single line :-)
Regards,
Vinay Sajip
.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue876421>
_______________________________________
More information about the Python-bugs-list
mailing list