[New-bugs-announce] [issue45027] Allow basicConfig to configure any logger, not just root

Greg Werbin report at bugs.python.org
Thu Aug 26 23:14:24 EDT 2021


New submission from Greg Werbin <outthere at me.gregwerbin.com>:

Hello all!

I am proposing to add a "logger=" kwarg to logging.basicConfig(), which would cause the configuration to be applied to the specified logger. The value of this parameter could be a string or a logging.Logger object. Omitting logger= or passing logger=None would be equivalent to the current behavior, using the root logger.

My rationale for this proposal is that the Python logging can be verbose to configure for "simple" use cases, and can be intimidating for new users, especially those who don't have prior experience with comparable logging frameworks in other languages. The simplicity of basicConfig() is great, but currently there is a very big usability gap between the "root logger only" case and the "fully manual configuration" case. This enhancement proposal would help to fill that gap.

I observe that many Python users tend to use basicConfig() even when they would be better served by configuring only the logger(s) needed for their own app/library. And I think many of these same Python users would appreciate the reduced verbosity and greater convenience of having a "basic config" option that they could apply to various loggers independently.

I know that I personally would use this enhanced basicConfig() all the time, and I hope that others feel the same way. I also believe that it would encourage adoption of sensible logging setups in a greater number of projects.

Here are the Git diffs, as rendered by Github:

* CPython: https://github.com/python/cpython/compare/main...gwerbin:gwerbin/basicconfig-any-logger

* Mypy (typeshed): https://github.com/python/mypy/compare/master...gwerbin:gwerbin/basicconfig-any-logger

----------
components: Library (Lib)
messages: 400391
nosy: gwerbin
priority: normal
severity: normal
status: open
title: Allow basicConfig to configure any logger, not just root
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45027>
_______________________________________


More information about the New-bugs-announce mailing list