log.py (1610B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\distutils\log.py 2 DEBUG = 1 3 INFO = 2 4 WARN = 3 5 ERROR = 4 6 FATAL = 5 7 import sys 8 9 class Log: 10 11 def __init__(self, threshold = WARN): 12 self.threshold = threshold 13 14 def _log(self, level, msg, args): 15 if level not in (DEBUG, 16 INFO, 17 WARN, 18 ERROR, 19 FATAL): 20 raise ValueError('%s wrong log level' % str(level)) 21 if level >= self.threshold: 22 if args: 23 msg = msg % args 24 if level in (WARN, ERROR, FATAL): 25 stream = sys.stderr 26 else: 27 stream = sys.stdout 28 stream.write('%s\n' % msg) 29 stream.flush() 30 31 def log(self, level, msg, *args): 32 self._log(level, msg, args) 33 34 def debug(self, msg, *args): 35 self._log(DEBUG, msg, args) 36 37 def info(self, msg, *args): 38 self._log(INFO, msg, args) 39 40 def warn(self, msg, *args): 41 self._log(WARN, msg, args) 42 43 def error(self, msg, *args): 44 self._log(ERROR, msg, args) 45 46 def fatal(self, msg, *args): 47 self._log(FATAL, msg, args) 48 49 50 _global_log = Log() 51 log = _global_log.log 52 debug = _global_log.debug 53 info = _global_log.info 54 warn = _global_log.warn 55 error = _global_log.error 56 fatal = _global_log.fatal 57 58 def set_threshold(level): 59 old = _global_log.threshold 60 _global_log.threshold = level 61 return old 62 63 64 def set_verbosity(v): 65 if v <= 0: 66 set_threshold(WARN) 67 elif v == 1: 68 set_threshold(INFO) 69 elif v >= 2: 70 set_threshold(DEBUG)