Aluode/PerceptionLabPortable
0
1"""2A simple log mechanism styled after PEP 282.3 4Retained for compatibility and should not be used.5"""6 7import logging8import warnings9 10from ._log import log as _global_log11 12DEBUG = logging.DEBUG13INFO = logging.INFO14WARN = logging.WARN15ERROR = logging.ERROR16FATAL = logging.FATAL17 18log = _global_log.log19debug = _global_log.debug20info = _global_log.info21warn = _global_log.warning22error = _global_log.error23fatal = _global_log.fatal24 25 26def set_threshold(level):27 orig = _global_log.level28 _global_log.setLevel(level)29 return orig30 31 32def set_verbosity(v):33 if v <= 0:34 set_threshold(logging.WARN)35 elif v == 1:36 set_threshold(logging.INFO)37 elif v >= 2:38 set_threshold(logging.DEBUG)39 40 41class Log(logging.Logger):42 """distutils.log.Log is deprecated, please use an alternative from `logging`."""43 44 def __init__(self, threshold=WARN):45 warnings.warn(Log.__doc__) # avoid DeprecationWarning to ensure warn is shown46 super().__init__(__name__, level=threshold)47 48 @property49 def threshold(self):50 return self.level51 52 @threshold.setter53 def threshold(self, level):54 self.setLevel(level)55 56 warn = logging.Logger.warning57 