summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-12-26 16:10:22 -0500
committerJason R. Coombs <jaraco@jaraco.com>2021-12-26 16:30:01 -0500
commit16326183595beb160242e954d9c30fad0c99e526 (patch)
tree959c348860552a4880167cf6a2fc8368fc682143
parent2540fef72bc680a0ed92a94d73bf01cdd30044fa (diff)
downloadwheel-git-python-logging-compat.tar.gz
Ensure logging is configured even on older Setuptools versions.python-logging-compat
-rw-r--r--src/wheel/_setuptools_logging.py23
-rw-r--r--src/wheel/util.py8
2 files changed, 31 insertions, 0 deletions
diff --git a/src/wheel/_setuptools_logging.py b/src/wheel/_setuptools_logging.py
new file mode 100644
index 0000000..70efa06
--- /dev/null
+++ b/src/wheel/_setuptools_logging.py
@@ -0,0 +1,23 @@
+# copied from setuptools.logging, omitting monkeypatching
+import sys
+import logging
+
+
+def _not_warning(record):
+ return record.levelno < logging.WARNING
+
+
+def configure():
+ """
+ Configure logging to emit warning and above to stderr
+ and everything else to stdout. This behavior is provided
+ for compatibilty with distutils.log but may change in
+ the future.
+ """
+ err_handler = logging.StreamHandler()
+ err_handler.setLevel(logging.WARNING)
+ out_handler = logging.StreamHandler(sys.stdout)
+ out_handler.addFilter(_not_warning)
+ handlers = err_handler, out_handler
+ logging.basicConfig(
+ format="{message}", style='{', handlers=handlers, level=logging.DEBUG)
diff --git a/src/wheel/util.py b/src/wheel/util.py
index af470b5..775433f 100644
--- a/src/wheel/util.py
+++ b/src/wheel/util.py
@@ -5,6 +5,14 @@ import logging
log = logging.getLogger('wheel')
+# ensure Python logging is configured
+try:
+ __import__('setuptools.logging')
+except ImportError:
+ # setuptools < ??
+ from . import _setuptools_logging
+ _setuptools_logging.configure()
+
def urlsafe_b64encode(data: bytes) -> bytes:
"""urlsafe_b64encode without padding"""