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.

Title: logging.getLogger accepts name='root' leading to confusion
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: vinay.sajip Nosy List: rhettinger, vinay.sajip, yurzo
Priority: normal Keywords: patch

Created on 2019-08-01 23:22 by yurzo, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 15077 merged vinay.sajip, 2019-08-02 13:05
Messages (3)
msg348877 - (view) Author: Damian Yurzola (yurzo) Date: 2019-08-01 23:22
'root' should be a reserved name to avoid this:

>>> import logging
>>> a = logging.getLogger()
>>> b = logging.getLogger('root')
>>> a is b
msg348888 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-08-02 06:57
It looks like the issue is that the root logger is missing from the manager's loggerDict.

A suggested fix is to change the creation of the loggerDict in the Manager class:

-       self.loggerDict = {}
+       self.loggerDict = { rootnode}

This may have been omitted from the initial design to avoid reference cycles; however, with the advent of garbage collection this should no longer be an issue.  Alternatively, a weak reference could be used.
msg348905 - (view) Author: Vinay Sajip (vinay.sajip) * (Python committer) Date: 2019-08-02 15:53
New changeset cb65b3a4f484ce71dcb76a918af98c7015513025 by Vinay Sajip in branch 'master':
bpo-37742: Return the root logger when logging.getLogger('root') is c… (#15077)
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81923
2019-08-02 16:01:28vinay.sajipsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-08-02 15:53:04vinay.sajipsetmessages: + msg348905
2019-08-02 13:05:26vinay.sajipsetkeywords: + patch
stage: patch review
pull_requests: + pull_request14824
2019-08-02 13:04:51vinay.sajipsetassignee: vinay.sajip
2019-08-02 06:57:14rhettingersetnosy: + rhettinger
messages: + msg348888
2019-08-02 01:42:12xtreaksetnosy: + vinay.sajip
2019-08-01 23:22:33yurzocreate