annotate 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
rev   line source
jpayne@68 1 import inspect
jpayne@68 2 import logging
jpayne@68 3 import sys
jpayne@68 4
jpayne@68 5 from . import monkey
jpayne@68 6
jpayne@68 7 import distutils.log
jpayne@68 8
jpayne@68 9
jpayne@68 10 def _not_warning(record):
jpayne@68 11 return record.levelno < logging.WARNING
jpayne@68 12
jpayne@68 13
jpayne@68 14 def configure():
jpayne@68 15 """
jpayne@68 16 Configure logging to emit warning and above to stderr
jpayne@68 17 and everything else to stdout. This behavior is provided
jpayne@68 18 for compatibility with distutils.log but may change in
jpayne@68 19 the future.
jpayne@68 20 """
jpayne@68 21 err_handler = logging.StreamHandler()
jpayne@68 22 err_handler.setLevel(logging.WARNING)
jpayne@68 23 out_handler = logging.StreamHandler(sys.stdout)
jpayne@68 24 out_handler.addFilter(_not_warning)
jpayne@68 25 handlers = err_handler, out_handler
jpayne@68 26 logging.basicConfig(
jpayne@68 27 format="{message}", style='{', handlers=handlers, level=logging.DEBUG
jpayne@68 28 )
jpayne@68 29 if inspect.ismodule(distutils.dist.log):
jpayne@68 30 monkey.patch_func(set_threshold, distutils.log, 'set_threshold')
jpayne@68 31 # For some reason `distutils.log` module is getting cached in `distutils.dist`
jpayne@68 32 # and then loaded again when patched,
jpayne@68 33 # implying: id(distutils.log) != id(distutils.dist.log).
jpayne@68 34 # Make sure the same module object is used everywhere:
jpayne@68 35 distutils.dist.log = distutils.log
jpayne@68 36
jpayne@68 37
jpayne@68 38 def set_threshold(level: int):
jpayne@68 39 logging.root.setLevel(level * 10)
jpayne@68 40 return set_threshold.unpatched(level)