This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: fileConfig() disables any previously-used "named" loggers, even when getLogger() is called again.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Bob.Igo, python-dev, vinay.sajip
Priority: normal Keywords:

Created on 2013-03-22 16:45 by Bob.Igo, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg184982 - (view) Author: Bob Igo (Bob.Igo) Date: 2013-03-22 16:45
I am aware of the described behavior of fileConfig() when disable_existing_loggers is True, but what I am seeing happens whether disable_existing_loggers is True or False, and it also affects loggers obtained via future, fresh calls to getLogger(name).

Here's an example where disable_existing_loggers is True, but as I said, the same happens when it's False:

>>> import logging.config
>>> logging.config.fileConfig('unit_test_logging.conf')
>>> logger = logging.getLogger("foo")
>>> logger.critical("test")
2013-03-21 23:33:04,621    foo    CRITICAL    test
>>> logging.config.fileConfig('unit_test_logging.conf')
>>> logger = logging.getLogger("foo")
>>> logger.critical("test")
>>>

Note that the final logging attempt silently fails. The thing that appears to break logging for ever is the second fileConfig() call, and not the following getLogger() call.

I can get a fresh logger with a different name and use it. (Continued from the above session):

>>> logger = logging.getLogger("bar")
>>> logger.critical("test")
2013-03-21 23:38:35,613    bar    CRITICAL    test


This issue does not affect the root logger, when no name is given to getLogger():

>>> import logging.config
>>> logging.config.fileConfig('unit_test_logging.conf')
>>> logger = logging.getLogger()
>>> logger.critical("test")
2013-03-22 11:49:29,957    root    CRITICAL    test
>>> logging.config.fileConfig('unit_test_logging.conf')
>>> logger = logging.getLogger()
>>> logger.critical("test")
2013-03-22 11:49:44,966    root    CRITICAL    test


However, it _does_ affect the root logger when "root" is given as the name to getLogger():

>>> import logging.config
>>> logging.config.fileConfig('unit_test_logging.conf')
>>> logger = logging.getLogger("root")
>>> logger.critical("test")
2013-03-22 12:42:49,742	root	CRITICAL	test
>>> logging.config.fileConfig('unit_test_logging.conf')
>>> logger = logging.getLogger("root")
>>> logger.critical("test")
>>> 

I can attach the logging config file if desired, but it looks like the issue is unrelated. I will say that I'm relying on the root logger for all my logging, but that I use a different name to differentiate how the log is written.
msg185011 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2013-03-22 21:50
The logger obtained by logging.getLogger('root') is not the root logger, but a child of the root logger.

Please post your configuration, ideally the smallest version which allows you to reproduce the failure.
msg185019 - (view) Author: Bob Igo (Bob.Igo) Date: 2013-03-22 23:49
Any configuration I tried still generates the bug, but here's a pared-down config file:

[loggers]
keys=root

[handlers]
keys=screen

[formatters]
keys=

[logger_root]
level=DEBUG
handlers=screen

[handler_screen]
level=DEBUG
class=StreamHandler
args=(sys.stdout,)
formatter=
msg185038 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-03-23 11:23
New changeset 533b4a1d2b23 by Vinay Sajip in branch '2.7':
Issue #17521: Corrected non-enabling of logger following two calls to fileConfig().
http://hg.python.org/cpython/rev/533b4a1d2b23

New changeset 49d54e4d95df by Vinay Sajip in branch '3.2':
Issue #17521: Corrected non-enabling of logger following two calls to fileConfig().
http://hg.python.org/cpython/rev/49d54e4d95df

New changeset 1f6cda549b85 by Vinay Sajip in branch '3.3':
Issue #17521: Merged fix from 3.2.
http://hg.python.org/cpython/rev/1f6cda549b85

New changeset aa01eb949636 by Vinay Sajip in branch 'default':
Closes #17521: Merged fix from 3.3.
http://hg.python.org/cpython/rev/aa01eb949636
History
Date User Action Args
2022-04-11 14:57:43adminsetgithub: 61723
2013-03-23 11:23:27python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg185038

resolution: fixed
stage: resolved
2013-03-22 23:49:25Bob.Igosetmessages: + msg185019
2013-03-22 21:50:54vinay.sajipsetmessages: + msg185011
2013-03-22 19:30:22ned.deilysetnosy: + vinay.sajip
2013-03-22 16:45:50Bob.Igocreate