bpo-37742: Return the root logger when logging.getLogger('root') is c… (#15077)
* bpo-37742: Return the root logger when logging.getLogger('root') is called.
* Added type check guard on logger name in logging.getLogger() and refined a test.
diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 645e0b3..62a87a7 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -2024,10 +2024,9 @@
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):
"""
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 6507d79..dca744c 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -4856,6 +4856,7 @@
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)