comparison env/lib/python3.7/site-packages/virtualenv/report.py @ 5:9b1c78e6ba9c draft default tip

"planemo upload commit 6c0a8142489327ece472c84e558c47da711a9142"
author shellac
date Mon, 01 Jun 2020 08:59:25 -0400
parents 79f47841a781
children
comparison
equal deleted inserted replaced
4:79f47841a781 5:9b1c78e6ba9c
1 from __future__ import absolute_import, unicode_literals
2
3 import logging
4 import sys
5
6 from virtualenv.util.six import ensure_str
7
8 LEVELS = {
9 0: logging.CRITICAL,
10 1: logging.ERROR,
11 2: logging.WARNING,
12 3: logging.INFO,
13 4: logging.DEBUG,
14 5: logging.NOTSET,
15 }
16
17 MAX_LEVEL = max(LEVELS.keys())
18 LOGGER = logging.getLogger()
19
20
21 def setup_report(verbose, quiet):
22 verbosity = max(verbose - quiet, 0)
23 _clean_handlers(LOGGER)
24 if verbosity > MAX_LEVEL:
25 verbosity = MAX_LEVEL # pragma: no cover
26 level = LEVELS[verbosity]
27 msg_format = "%(message)s"
28 filelock_logger = logging.getLogger("filelock")
29 if level <= logging.DEBUG:
30 locate = "module"
31 msg_format = "%(relativeCreated)d {} [%(levelname)s %({})s:%(lineno)d]".format(msg_format, locate)
32 filelock_logger.setLevel(level)
33 else:
34 filelock_logger.setLevel(logging.WARN)
35
36 formatter = logging.Formatter(ensure_str(msg_format))
37 stream_handler = logging.StreamHandler(stream=sys.stdout)
38 stream_handler.setLevel(level)
39 LOGGER.setLevel(logging.NOTSET)
40 stream_handler.setFormatter(formatter)
41 LOGGER.addHandler(stream_handler)
42 level_name = logging.getLevelName(level)
43 logging.debug("setup logging to %s", level_name)
44 return verbosity
45
46
47 def _clean_handlers(log):
48 for log_handler in list(log.handlers): # remove handlers of libraries
49 log.removeHandler(log_handler)