Skip to content

Commit 6d26f3e

Browse files
committed
Issue #8201: logging: Handle config errors when non-ASCII and Unicode logger names exist at the same time.
1 parent ae3dd04 commit 6d26f3e

3 files changed

Lines changed: 15 additions & 2 deletions

File tree

Lib/logging/config.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ def _resolve(name):
9898
def _strip_spaces(alist):
9999
return map(lambda x: x.strip(), alist)
100100

101+
def _encoded(s):
102+
return s if isinstance(s, str) else s.encode('utf-8')
103+
101104
def _create_formatters(cp):
102105
"""Create and return formatters"""
103106
flist = cp.get("formatters", "keys")
@@ -208,7 +211,7 @@ def _install_loggers(cp, handlers, disable_existing_loggers):
208211
#avoid disabling child loggers of explicitly
209212
#named loggers. With a sorted list it is easier
210213
#to find the child loggers.
211-
existing.sort()
214+
existing.sort(key=_encoded)
212215
#We'll keep the list of existing loggers
213216
#which are children of named loggers here...
214217
child_loggers = []
@@ -580,7 +583,7 @@ def configure(self):
580583
#avoid disabling child loggers of explicitly
581584
#named loggers. With a sorted list it is easier
582585
#to find the child loggers.
583-
existing.sort()
586+
existing.sort(key=_encoded)
584587
#We'll keep the list of existing loggers
585588
#which are children of named loggers here...
586589
child_loggers = []

Lib/test/test_logging.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,12 @@ def setUp(self):
6868
finally:
6969
logging._releaseLock()
7070

71+
# Set two unused loggers: one non-ASCII and one Unicode.
72+
# This is to test correct operation when sorting existing
73+
# loggers in the configuration code. See issue 8201.
74+
logging.getLogger("\xab\xd7\xbb")
75+
logging.getLogger(u"\u013f\u00d6\u0047")
76+
7177
self.root_logger = logging.getLogger("")
7278
self.original_logging_level = self.root_logger.getEffectiveLevel()
7379

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Core and Builtins
2929
Library
3030
-------
3131

32+
- Issue #8201: logging: Handle situation of non-ASCII and Unicode
33+
logger names existing at the same time, causing a Unicode error
34+
when configuration code attempted to sort the existing loggers.
35+
3236
- Issue #8200: logging: Handle errors when multiprocessing is not
3337
fully loaded when logging occurs.
3438

0 commit comments

Comments
 (0)