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
c75470f9b7
commit
0c45776c07
@ -118,6 +118,7 @@ class SphinxWarningLogRecord(SphinxLogRecord):
|
|||||||
|
|
||||||
class SphinxLoggerAdapter(logging.LoggerAdapter):
|
class SphinxLoggerAdapter(logging.LoggerAdapter):
|
||||||
"""LoggerAdapter allowing ``type`` and ``subtype`` keywords."""
|
"""LoggerAdapter allowing ``type`` and ``subtype`` keywords."""
|
||||||
|
KEYWORDS = ['type', 'subtype', 'location', 'nonl', 'color']
|
||||||
|
|
||||||
def log(self, level: Union[int, str], msg: str, *args: Any, **kwargs: Any) -> None:
|
def log(self, level: Union[int, str], msg: str, *args: Any, **kwargs: Any) -> None:
|
||||||
if isinstance(level, int):
|
if isinstance(level, int):
|
||||||
@ -131,16 +132,9 @@ class SphinxLoggerAdapter(logging.LoggerAdapter):
|
|||||||
|
|
||||||
def process(self, msg: str, kwargs: Dict) -> Tuple[str, Dict]: # type: ignore
|
def process(self, msg: str, kwargs: Dict) -> Tuple[str, Dict]: # type: ignore
|
||||||
extra = kwargs.setdefault('extra', {})
|
extra = kwargs.setdefault('extra', {})
|
||||||
if 'type' in kwargs:
|
for keyword in self.KEYWORDS:
|
||||||
extra['type'] = kwargs.pop('type')
|
if keyword in kwargs:
|
||||||
if 'subtype' in kwargs:
|
extra[keyword] = kwargs.pop(keyword)
|
||||||
extra['subtype'] = kwargs.pop('subtype')
|
|
||||||
if 'location' in kwargs:
|
|
||||||
extra['location'] = kwargs.pop('location')
|
|
||||||
if 'nonl' in kwargs:
|
|
||||||
extra['nonl'] = kwargs.pop('nonl')
|
|
||||||
if 'color' in kwargs:
|
|
||||||
extra['color'] = kwargs.pop('color')
|
|
||||||
|
|
||||||
return msg, kwargs
|
return msg, kwargs
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user