Mercurial > repos > rliterman > csp2
comparison CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/setuptools/logging.py @ 68:5028fdace37b
planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author | jpayne |
---|---|
date | Tue, 18 Mar 2025 16:23:26 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
67:0e9998148a16 | 68:5028fdace37b |
---|---|
1 import inspect | |
2 import logging | |
3 import sys | |
4 | |
5 from . import monkey | |
6 | |
7 import distutils.log | |
8 | |
9 | |
10 def _not_warning(record): | |
11 return record.levelno < logging.WARNING | |
12 | |
13 | |
14 def configure(): | |
15 """ | |
16 Configure logging to emit warning and above to stderr | |
17 and everything else to stdout. This behavior is provided | |
18 for compatibility with distutils.log but may change in | |
19 the future. | |
20 """ | |
21 err_handler = logging.StreamHandler() | |
22 err_handler.setLevel(logging.WARNING) | |
23 out_handler = logging.StreamHandler(sys.stdout) | |
24 out_handler.addFilter(_not_warning) | |
25 handlers = err_handler, out_handler | |
26 logging.basicConfig( | |
27 format="{message}", style='{', handlers=handlers, level=logging.DEBUG | |
28 ) | |
29 if inspect.ismodule(distutils.dist.log): | |
30 monkey.patch_func(set_threshold, distutils.log, 'set_threshold') | |
31 # For some reason `distutils.log` module is getting cached in `distutils.dist` | |
32 # and then loaded again when patched, | |
33 # implying: id(distutils.log) != id(distutils.dist.log). | |
34 # Make sure the same module object is used everywhere: | |
35 distutils.dist.log = distutils.log | |
36 | |
37 | |
38 def set_threshold(level: int): | |
39 logging.root.setLevel(level * 10) | |
40 return set_threshold.unpatched(level) |