classification
Title: logging.getLogger accepts name='root' leading to confusion
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
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 2019-08-02 16:01 by vinay.sajip. 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.name
'root'
>>> b.name
'root'
>>> a is b
False
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.name: 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)
https://github.com/python/cpython/commit/cb65b3a4f484ce71dcb76a918af98c7015513025
History
Date User Action Args
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