ยปCore Development>Code coverage>Lib/distutils/log.py

Python code coverage for Lib/distutils/log.py

#countcontent
1n/a"""A simple log mechanism styled after PEP 282."""
2n/a
3n/a# The class here is styled after PEP 282 so that it could later be
4n/a# replaced with a standard Python logging implementation.
5n/a
6n/aDEBUG = 1
7n/aINFO = 2
8n/aWARN = 3
9n/aERROR = 4
10n/aFATAL = 5
11n/a
12n/aimport sys
13n/a
14n/aclass Log:
15n/a
16n/a def __init__(self, threshold=WARN):
17n/a self.threshold = threshold
18n/a
19n/a def _log(self, level, msg, args):
20n/a if level not in (DEBUG, INFO, WARN, ERROR, FATAL):
21n/a raise ValueError('%s wrong log level' % str(level))
22n/a
23n/a if level >= self.threshold:
24n/a if args:
25n/a msg = msg % args
26n/a if level in (WARN, ERROR, FATAL):
27n/a stream = sys.stderr
28n/a else:
29n/a stream = sys.stdout
30n/a if stream.errors == 'strict':
31n/a # emulate backslashreplace error handler
32n/a encoding = stream.encoding
33n/a msg = msg.encode(encoding, "backslashreplace").decode(encoding)
34n/a stream.write('%s\n' % msg)
35n/a stream.flush()
36n/a
37n/a def log(self, level, msg, *args):
38n/a self._log(level, msg, args)
39n/a
40n/a def debug(self, msg, *args):
41n/a self._log(DEBUG, msg, args)
42n/a
43n/a def info(self, msg, *args):
44n/a self._log(INFO, msg, args)
45n/a
46n/a def warn(self, msg, *args):
47n/a self._log(WARN, msg, args)
48n/a
49n/a def error(self, msg, *args):
50n/a self._log(ERROR, msg, args)
51n/a
52n/a def fatal(self, msg, *args):
53n/a self._log(FATAL, msg, args)
54n/a
55n/a_global_log = Log()
56n/alog = _global_log.log
57n/adebug = _global_log.debug
58n/ainfo = _global_log.info
59n/awarn = _global_log.warn
60n/aerror = _global_log.error
61n/afatal = _global_log.fatal
62n/a
63n/adef set_threshold(level):
64n/a # return the old threshold for use from tests
65n/a old = _global_log.threshold
66n/a _global_log.threshold = level
67n/a return old
68n/a
69n/adef set_verbosity(v):
70n/a if v <= 0:
71n/a set_threshold(WARN)
72n/a elif v == 1:
73n/a set_threshold(INFO)
74n/a elif v >= 2:
75n/a set_threshold(DEBUG)