Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/setuptools/logging.py: 40%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import inspect
2import logging
3import sys
5from . import monkey
7import distutils.log
10def _not_warning(record):
11 return record.levelno < logging.WARNING
14def 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
38def set_threshold(level):
39 logging.root.setLevel(level * 10)
40 return set_threshold.unpatched(level)