mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Refactor SphinxLoggerAdapter
This commit is contained in:
parent
aa65a19466
commit
25a078655b
@ -124,25 +124,13 @@ class sphinx_domains(object):
|
||||
|
||||
|
||||
class WarningStream(object):
|
||||
level_mapping = {
|
||||
'DEBUG': logger.debug,
|
||||
'INFO': logger.info,
|
||||
'WARNING': logger.warning,
|
||||
'ERROR': logger.error,
|
||||
'SEVERE': logger.critical,
|
||||
}
|
||||
|
||||
def write(self, text):
|
||||
matched = report_re.search(text)
|
||||
if not matched:
|
||||
logger.warning(text.rstrip("\r\n"))
|
||||
else:
|
||||
location, type, level, message = matched.groups()
|
||||
if type in self.level_mapping:
|
||||
logger_method = self.level_mapping.get(type)
|
||||
logger_method(message, location=location)
|
||||
else:
|
||||
logger.warning(text.rstrip("\r\n"))
|
||||
logger.log(type, message, location=location)
|
||||
|
||||
|
||||
class LoggingReporter(Reporter):
|
||||
|
@ -31,6 +31,18 @@ if False:
|
||||
VERBOSE = 15
|
||||
DEBUG2 = 5
|
||||
|
||||
LEVEL_NAMES = defaultdict(lambda: logging.WARNING) # type: Dict[str, int]
|
||||
LEVEL_NAMES.update({
|
||||
'CRITICAL': logging.CRITICAL,
|
||||
'SEVERE': logging.CRITICAL,
|
||||
'ERROR': logging.ERROR,
|
||||
'WARNING': logging.WARNING,
|
||||
'INFO': logging.INFO,
|
||||
'VERBOSE': VERBOSE,
|
||||
'DEBUG': logging.DEBUG,
|
||||
'DEBUG2': DEBUG2,
|
||||
})
|
||||
|
||||
VERBOSITY_MAP = defaultdict(lambda: 0) # type: Dict[int, int]
|
||||
VERBOSITY_MAP.update({
|
||||
0: logging.INFO,
|
||||
@ -97,6 +109,14 @@ class SphinxLoggerAdapter(logging.LoggerAdapter):
|
||||
|
||||
self.warning(message, **kwargs)
|
||||
|
||||
def log(self, level, msg, *args, **kwargs):
|
||||
# type: (Union[int, str], unicode, Any, Any) -> None
|
||||
if isinstance(level, int):
|
||||
super(SphinxLoggerAdapter, self).log(level, msg, *args, **kwargs)
|
||||
else:
|
||||
levelno = LEVEL_NAMES.get(level)
|
||||
super(SphinxLoggerAdapter, self).log(levelno, msg, *args, **kwargs)
|
||||
|
||||
def verbose(self, msg, *args, **kwargs):
|
||||
# type: (unicode, Any, Any) -> None
|
||||
self.log(VERBOSE, msg, *args, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user