summaryrefslogtreecommitdiff
path: root/setuptools/logging.py
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2022-05-09 10:42:04 -0400
committerJason R. Coombs <jaraco@jaraco.com>2022-05-09 10:42:56 -0400
commit9116c7eb52504bec77d26881d2c28e427dc52143 (patch)
tree6becb88401eb15bdff6fc924211894e6d9c277d1 /setuptools/logging.py
parent8d12d6196c369c7cf0164a1202e968dd68a2cb6c (diff)
parente009a87b5578cb16099b697ba8395c8f6bdd70f3 (diff)
downloadpython-setuptools-git-debt/remove-easy-install.tar.gz
Merge branch 'main' into debt/remove-easy-installdebt/remove-easy-install
Diffstat (limited to 'setuptools/logging.py')
-rw-r--r--setuptools/logging.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/setuptools/logging.py b/setuptools/logging.py
new file mode 100644
index 00000000..15b57613
--- /dev/null
+++ b/setuptools/logging.py
@@ -0,0 +1,36 @@
+import sys
+import logging
+import distutils.log
+from . import monkey
+
+
+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)
+ monkey.patch_func(set_threshold, distutils.log, 'set_threshold')
+
+ # For some reason `distutils.log` module is getting cached in `distutils.dist`
+ # and then loaded again when patched,
+ # implying: id(distutils.log) != id(distutils.dist.log).
+ # Make sure the same module object is used everywhere:
+ distutils.dist.log = distutils.log
+
+
+def set_threshold(level):
+ logging.root.setLevel(level*10)
+ return set_threshold.unpatched(level)