Path: blob/main/test/lib/python3.9/site-packages/setuptools/_distutils/log.py
4799 views
"""A simple log mechanism styled after PEP 282."""12# The class here is styled after PEP 282 so that it could later be3# replaced with a standard Python logging implementation.45import sys67DEBUG = 18INFO = 29WARN = 310ERROR = 411FATAL = 5121314class Log:1516def __init__(self, threshold=WARN):17self.threshold = threshold1819def _log(self, level, msg, args):20if level not in (DEBUG, INFO, WARN, ERROR, FATAL):21raise ValueError('%s wrong log level' % str(level))2223if level >= self.threshold:24if args:25msg = msg % args26if level in (WARN, ERROR, FATAL):27stream = sys.stderr28else:29stream = sys.stdout30try:31stream.write('%s\n' % msg)32except UnicodeEncodeError:33# emulate backslashreplace error handler34encoding = stream.encoding35msg = msg.encode(encoding, "backslashreplace").decode(encoding)36stream.write('%s\n' % msg)37stream.flush()3839def log(self, level, msg, *args):40self._log(level, msg, args)4142def debug(self, msg, *args):43self._log(DEBUG, msg, args)4445def info(self, msg, *args):46self._log(INFO, msg, args)4748def warn(self, msg, *args):49self._log(WARN, msg, args)5051def error(self, msg, *args):52self._log(ERROR, msg, args)5354def fatal(self, msg, *args):55self._log(FATAL, msg, args)565758_global_log = Log()59log = _global_log.log60debug = _global_log.debug61info = _global_log.info62warn = _global_log.warn63error = _global_log.error64fatal = _global_log.fatal656667def set_threshold(level):68# return the old threshold for use from tests69old = _global_log.threshold70_global_log.threshold = level71return old727374def set_verbosity(v):75if v <= 0:76set_threshold(WARN)77elif v == 1:78set_threshold(INFO)79elif v >= 2:80set_threshold(DEBUG)818283