Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
keewenaw
GitHub Repository: keewenaw/ethereum-wallet-cracker
Path: blob/main/test/lib/python3.9/site-packages/setuptools/_distutils/log.py
4799 views
1
"""A simple log mechanism styled after PEP 282."""
2
3
# The class here is styled after PEP 282 so that it could later be
4
# replaced with a standard Python logging implementation.
5
6
import sys
7
8
DEBUG = 1
9
INFO = 2
10
WARN = 3
11
ERROR = 4
12
FATAL = 5
13
14
15
class Log:
16
17
def __init__(self, threshold=WARN):
18
self.threshold = threshold
19
20
def _log(self, level, msg, args):
21
if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
22
raise ValueError('%s wrong log level' % str(level))
23
24
if level >= self.threshold:
25
if args:
26
msg = msg % args
27
if level in (WARN, ERROR, FATAL):
28
stream = sys.stderr
29
else:
30
stream = sys.stdout
31
try:
32
stream.write('%s\n' % msg)
33
except UnicodeEncodeError:
34
# emulate backslashreplace error handler
35
encoding = stream.encoding
36
msg = msg.encode(encoding, "backslashreplace").decode(encoding)
37
stream.write('%s\n' % msg)
38
stream.flush()
39
40
def log(self, level, msg, *args):
41
self._log(level, msg, args)
42
43
def debug(self, msg, *args):
44
self._log(DEBUG, msg, args)
45
46
def info(self, msg, *args):
47
self._log(INFO, msg, args)
48
49
def warn(self, msg, *args):
50
self._log(WARN, msg, args)
51
52
def error(self, msg, *args):
53
self._log(ERROR, msg, args)
54
55
def fatal(self, msg, *args):
56
self._log(FATAL, msg, args)
57
58
59
_global_log = Log()
60
log = _global_log.log
61
debug = _global_log.debug
62
info = _global_log.info
63
warn = _global_log.warn
64
error = _global_log.error
65
fatal = _global_log.fatal
66
67
68
def set_threshold(level):
69
# return the old threshold for use from tests
70
old = _global_log.threshold
71
_global_log.threshold = level
72
return old
73
74
75
def set_verbosity(v):
76
if v <= 0:
77
set_threshold(WARN)
78
elif v == 1:
79
set_threshold(INFO)
80
elif v >= 2:
81
set_threshold(DEBUG)
82
83