Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
logging.py39 linesDownload Raw Back to setuptools
1import sys2import inspect3import logging4import distutils.log5from . import monkey6 7 8def _not_warning(record):9    return record.levelno < logging.WARNING10 11 12def configure():13    """14    Configure logging to emit warning and above to stderr15    and everything else to stdout. This behavior is provided16    for compatibility with distutils.log but may change in17    the future.18    """19    err_handler = logging.StreamHandler()20    err_handler.setLevel(logging.WARNING)21    out_handler = logging.StreamHandler(sys.stdout)22    out_handler.addFilter(_not_warning)23    handlers = err_handler, out_handler24    logging.basicConfig(25        format="{message}", style='{', handlers=handlers, level=logging.DEBUG26    )27    if inspect.ismodule(distutils.dist.log):28        monkey.patch_func(set_threshold, distutils.log, 'set_threshold')29        # For some reason `distutils.log` module is getting cached in `distutils.dist`30        # and then loaded again when patched,31        # implying: id(distutils.log) != id(distutils.dist.log).32        # Make sure the same module object is used everywhere:33        distutils.dist.log = distutils.log34 35 36def set_threshold(level):37    logging.root.setLevel(level * 10)38    return set_threshold.unpatched(level)39 
codekingpro/portable-devtools · Team Ai