Path: blob/master/venv/Lib/site-packages/setuptools/_distutils/log.py
811 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.45DEBUG = 16INFO = 27WARN = 38ERROR = 49FATAL = 51011import sys1213class Log:1415def __init__(self, threshold=WARN):16self.threshold = threshold1718def _log(self, level, msg, args):19if level not in (DEBUG, INFO, WARN, ERROR, FATAL):20raise ValueError('%s wrong log level' % str(level))2122if level >= self.threshold:23if args:24msg = msg % args25if level in (WARN, ERROR, FATAL):26stream = sys.stderr27else:28stream = sys.stdout29try:30stream.write('%s\n' % msg)31except UnicodeEncodeError:32# emulate backslashreplace error handler33encoding = stream.encoding34msg = msg.encode(encoding, "backslashreplace").decode(encoding)35stream.write('%s\n' % msg)36stream.flush()3738def log(self, level, msg, *args):39self._log(level, msg, args)4041def debug(self, msg, *args):42self._log(DEBUG, msg, args)4344def info(self, msg, *args):45self._log(INFO, msg, args)4647def warn(self, msg, *args):48self._log(WARN, msg, args)4950def error(self, msg, *args):51self._log(ERROR, msg, args)5253def fatal(self, msg, *args):54self._log(FATAL, msg, args)5556_global_log = Log()57log = _global_log.log58debug = _global_log.debug59info = _global_log.info60warn = _global_log.warn61error = _global_log.error62fatal = _global_log.fatal6364def set_threshold(level):65# return the old threshold for use from tests66old = _global_log.threshold67_global_log.threshold = level68return old6970def set_verbosity(v):71if v <= 0:72set_threshold(WARN)73elif v == 1:74set_threshold(INFO)75elif v >= 2:76set_threshold(DEBUG)777879