"""A simple log mechanism styled after PEP 282."""# The class here is styled after PEP 282 so that it could later be# replaced with a standard Python logging implementation.DEBUG = 1INFO = 2WARN = 3ERROR = 4FATAL = 5import sysclass Log:def __init__(self, threshold=WARN):self.threshold = thresholddef _log(self, level, msg, args):if level not in (DEBUG, INFO, WARN, ERROR, FATAL):raise ValueError('%s wrong log level' % str(level))if level >= self.threshold:if args:msg = msg % argsif level in (WARN, ERROR, FATAL):stream = sys.stderrelse:stream = sys.stdoutif stream.errors == 'strict':# emulate backslashreplace error handlerencoding = stream.encodingmsg = msg.encode(encoding, "backslashreplace").decode(encoding)stream.write('%s\n' % msg)stream.flush()def log(self, level, msg, *args):self._log(level, msg, args)def debug(self, msg, *args):self._log(DEBUG, msg, args)def info(self, msg, *args):self._log(INFO, msg, args)def warn(self, msg, *args):self._log(WARN, msg, args)def error(self, msg, *args):self._log(ERROR, msg, args)def fatal(self, msg, *args):self._log(FATAL, msg, args)_global_log = Log()log = _global_log.logdebug = _global_log.debuginfo = _global_log.infowarn = _global_log.warnerror = _global_log.errorfatal = _global_log.fataldef set_threshold(level):# return the old threshold for use from testsold = _global_log.threshold_global_log.threshold = levelreturn olddef set_verbosity(v):if v <= 0:set_threshold(WARN)elif v == 1:set_threshold(INFO)elif v >= 2:set_threshold(DEBUG)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。