From 382037c446f45ebc2e91fd5144eda4dfa90c0281 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 26 Dec 2021 14:15:15 -0500 Subject: Add setuptools.log to supersede distutils.log. Ref #2973. --- setuptools/logging.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 setuptools/logging.py (limited to 'setuptools/logging.py') diff --git a/setuptools/logging.py b/setuptools/logging.py new file mode 100644 index 00000000..0ac47059 --- /dev/null +++ b/setuptools/logging.py @@ -0,0 +1,22 @@ +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) -- cgit v1.2.1 From b9cf7ff3ff907b5a805264b399b17e4ea6bec049 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 26 Dec 2021 15:23:28 -0500 Subject: Monkey patch distutils.log.set_threshold so the Python logger honors calls to it. --- setuptools/logging.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'setuptools/logging.py') diff --git a/setuptools/logging.py b/setuptools/logging.py index 0ac47059..dbead6e6 100644 --- a/setuptools/logging.py +++ b/setuptools/logging.py @@ -1,5 +1,7 @@ import sys import logging +import distutils.log +from . import monkey def _not_warning(record): @@ -20,3 +22,9 @@ def configure(): handlers = err_handler, out_handler logging.basicConfig( format="{message}", style='{', handlers=handlers, level=logging.DEBUG) + monkey.patch_func(set_threshold, distutils.log, 'set_threshold') + + +def set_threshold(level): + logging.root.setLevel(level*10) + return set_threshold.unpatched(level) -- cgit v1.2.1 From 0d491c616284933e35bb5d61a94828aed0c8d3f2 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Sat, 22 Jan 2022 12:56:09 +0000 Subject: Fix weird distutils.log reloading/caching situation For some reason `distutils.log` module is getting cached in `distutils.dist` and then loaded again when we have the opportunity to patch it. This implies: id(distutils.log) != id(distutils.dist.log). We need to make sure the same module object is used everywhere. --- setuptools/logging.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'setuptools/logging.py') diff --git a/setuptools/logging.py b/setuptools/logging.py index dbead6e6..56669c96 100644 --- a/setuptools/logging.py +++ b/setuptools/logging.py @@ -24,6 +24,12 @@ def configure(): 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 we have the opportunity to patch it. + # This implies: id(distutils.log) != id(distutils.dist.log). + # We need to make sure the same module object is used everywhere: + distutils.dist.log = distutils.log + def set_threshold(level): logging.root.setLevel(level*10) -- cgit v1.2.1 From 711b5267109a4b6799d002aa96fa913ab8bee231 Mon Sep 17 00:00:00 2001 From: Anderson Bravalheri Date: Sat, 22 Jan 2022 17:30:36 +0000 Subject: Update setuptools/logging.py Co-authored-by: Jason R. Coombs --- setuptools/logging.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'setuptools/logging.py') diff --git a/setuptools/logging.py b/setuptools/logging.py index 56669c96..15b57613 100644 --- a/setuptools/logging.py +++ b/setuptools/logging.py @@ -25,9 +25,9 @@ def configure(): 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 we have the opportunity to patch it. - # This implies: id(distutils.log) != id(distutils.dist.log). - # We need to make sure the same module object is used everywhere: + # 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 -- cgit v1.2.1