Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileConfig() disables any previously-used "named" loggers, even when getLogger() is called again. #61723

Closed
BobIgo mannequin opened this issue Mar 22, 2013 · 4 comments
Closed
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@BobIgo
Copy link
Mannequin

BobIgo mannequin commented Mar 22, 2013

BPO 17521
Nosy @vsajip

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2013-03-23.11:23:27.512>
created_at = <Date 2013-03-22.16:45:50.539>
labels = ['type-bug', 'library']
title = 'fileConfig() disables any previously-used "named" loggers, even when getLogger() is called again.'
updated_at = <Date 2013-03-23.11:23:27.509>
user = 'https://bugs.python.org/BobIgo'

bugs.python.org fields:

activity = <Date 2013-03-23.11:23:27.509>
actor = 'python-dev'
assignee = 'none'
closed = True
closed_date = <Date 2013-03-23.11:23:27.512>
closer = 'python-dev'
components = ['Library (Lib)']
creation = <Date 2013-03-22.16:45:50.539>
creator = 'Bob.Igo'
dependencies = []
files = []
hgrepos = []
issue_num = 17521
keywords = []
message_count = 4.0
messages = ['184982', '185011', '185019', '185038']
nosy_count = 3.0
nosy_names = ['vinay.sajip', 'python-dev', 'Bob.Igo']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue17521'
versions = ['Python 2.7']

@BobIgo
Copy link
Mannequin Author

BobIgo mannequin commented Mar 22, 2013

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.

@BobIgo BobIgo mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 22, 2013
@vsajip
Copy link
Member

vsajip commented Mar 22, 2013

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.

@BobIgo
Copy link
Mannequin Author

BobIgo mannequin commented Mar 22, 2013

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=

@python-dev
Copy link
Mannequin

python-dev mannequin commented Mar 23, 2013

New changeset 533b4a1d2b23 by Vinay Sajip in branch '2.7':
Issue bpo-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 bpo-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 bpo-17521: Merged fix from 3.2.
http://hg.python.org/cpython/rev/1f6cda549b85

New changeset aa01eb949636 by Vinay Sajip in branch 'default':
Closes bpo-17521: Merged fix from 3.3.
http://hg.python.org/cpython/rev/aa01eb949636

@python-dev python-dev mannequin closed this as completed Mar 23, 2013
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant