jpayne@68: import inspect jpayne@68: import logging jpayne@68: import sys jpayne@68: jpayne@68: from . import monkey jpayne@68: jpayne@68: import distutils.log jpayne@68: jpayne@68: jpayne@68: def _not_warning(record): jpayne@68: return record.levelno < logging.WARNING jpayne@68: jpayne@68: jpayne@68: def configure(): jpayne@68: """ jpayne@68: Configure logging to emit warning and above to stderr jpayne@68: and everything else to stdout. This behavior is provided jpayne@68: for compatibility with distutils.log but may change in jpayne@68: the future. jpayne@68: """ jpayne@68: err_handler = logging.StreamHandler() jpayne@68: err_handler.setLevel(logging.WARNING) jpayne@68: out_handler = logging.StreamHandler(sys.stdout) jpayne@68: out_handler.addFilter(_not_warning) jpayne@68: handlers = err_handler, out_handler jpayne@68: logging.basicConfig( jpayne@68: format="{message}", style='{', handlers=handlers, level=logging.DEBUG jpayne@68: ) jpayne@68: if inspect.ismodule(distutils.dist.log): jpayne@68: monkey.patch_func(set_threshold, distutils.log, 'set_threshold') jpayne@68: # For some reason `distutils.log` module is getting cached in `distutils.dist` jpayne@68: # and then loaded again when patched, jpayne@68: # implying: id(distutils.log) != id(distutils.dist.log). jpayne@68: # Make sure the same module object is used everywhere: jpayne@68: distutils.dist.log = distutils.log jpayne@68: jpayne@68: jpayne@68: def set_threshold(level: int): jpayne@68: logging.root.setLevel(level * 10) jpayne@68: return set_threshold.unpatched(level)