Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Lib/logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2024,10 +2024,9 @@ def getLogger(name=None):

If no name is specified, return the root logger.
"""
if name:
return Logger.manager.getLogger(name)
else:
if not name or isinstance(name, str) and name == root.name:
return root
return Logger.manager.getLogger(name)

def critical(msg, *args, **kwargs):
"""
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -4856,6 +4856,7 @@ def test_root_logger_aliases(self):
self.assertIs(root, logging.root)
self.assertIs(root, logging.getLogger(None))
self.assertIs(root, logging.getLogger(''))
self.assertIs(root, logging.getLogger('root'))
self.assertIs(root, logging.getLogger('foo').root)
self.assertIs(root, logging.getLogger('foo.bar').root)
self.assertIs(root, logging.getLogger('foo').parent)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
The logging.getLogger() API now returns the root logger when passed the name
'root', whereas previously it returned a non-root logger named 'root'. This
could affect cases where user code explicitly wants a non-root logger named
'root', or instantiates a logger using logging.getLogger(__name__) in some
top-level module called 'root.py'.