Issue #8201: logging: Handle config errors when non-ASCII and Unicode logger names exist at the same time.
diff --git a/Lib/logging/config.py b/Lib/logging/config.py
index 21e10c1..4f55c53 100644
--- a/Lib/logging/config.py
+++ b/Lib/logging/config.py
@@ -98,6 +98,9 @@
 def _strip_spaces(alist):
     return map(lambda x: x.strip(), alist)
 
+def _encoded(s):
+    return s if isinstance(s, str) else s.encode('utf-8')
+
 def _create_formatters(cp):
     """Create and return formatters"""
     flist = cp.get("formatters", "keys")
@@ -208,7 +211,7 @@
     #avoid disabling child loggers of explicitly
     #named loggers. With a sorted list it is easier
     #to find the child loggers.
-    existing.sort()
+    existing.sort(key=_encoded)
     #We'll keep the list of existing loggers
     #which are children of named loggers here...
     child_loggers = []
@@ -580,7 +583,7 @@
                 #avoid disabling child loggers of explicitly
                 #named loggers. With a sorted list it is easier
                 #to find the child loggers.
-                existing.sort()
+                existing.sort(key=_encoded)
                 #We'll keep the list of existing loggers
                 #which are children of named loggers here...
                 child_loggers = []
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index e3b9718..a918d6e 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -68,6 +68,12 @@
         finally:
             logging._releaseLock()
 
+        # Set two unused loggers: one non-ASCII and one Unicode.
+        # This is to test correct operation when sorting existing
+        # loggers in the configuration code. See issue 8201.
+        logging.getLogger("\xab\xd7\xbb")
+        logging.getLogger(u"\u013f\u00d6\u0047")
+
         self.root_logger = logging.getLogger("")
         self.original_logging_level = self.root_logger.getEffectiveLevel()