Skip to content
Snippets Groups Projects
Unverified Commit ec72f59b authored by Mashiro's avatar Mashiro Committed by GitHub
Browse files

[Enhance] Remove blink info and debug level message (#371)

* remove blink info debug msg

* minor refine

* minor refine
parent f3189918
No related branches found
No related tags found
No related merge requests found
...@@ -19,18 +19,24 @@ class MMFormatter(logging.Formatter): ...@@ -19,18 +19,24 @@ class MMFormatter(logging.Formatter):
Args: Args:
color (bool): Whether to use colorful format. filehandler is not color (bool): Whether to use colorful format. filehandler is not
allowed to use color format, otherwise it will be garbled. allowed to use color format, otherwise it will be garbled.
blink (bool): Whether to blink the ``INFO`` and ``DEBUG`` logging
level.
**kwargs: Keyword arguments passed to
:meth:`logging.Formatter.__init__`.
""" """
_color_mapping: dict = dict( _color_mapping: dict = dict(
ERROR='red', WARNING='yellow', INFO='white', DEBUG='green') ERROR='red', WARNING='yellow', INFO='white', DEBUG='green')
def __init__(self, color: bool = True, **kwargs): def __init__(self, color: bool = True, blink: bool = False, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
assert not (not color and blink), (
'blink should only be available when color is True')
# Get prefix format according to color. # Get prefix format according to color.
error_prefix = self._get_prefix('ERROR', color) error_prefix = self._get_prefix('ERROR', color, blink=True)
warn_prefix = self._get_prefix('WARNING', color) warn_prefix = self._get_prefix('WARNING', color, blink=True)
info_prefix = self._get_prefix('INFO', color) info_prefix = self._get_prefix('INFO', color, blink)
debug_prefix = self._get_prefix('DEBUG', color) debug_prefix = self._get_prefix('DEBUG', color, blink)
# Config output format. # Config output format.
self.err_format = (f'%(asctime)s - %(name)s - {error_prefix} - ' self.err_format = (f'%(asctime)s - %(name)s - {error_prefix} - '
'%(pathname)s - %(funcName)s - %(lineno)d - ' '%(pathname)s - %(funcName)s - %(lineno)d - '
...@@ -42,21 +48,22 @@ class MMFormatter(logging.Formatter): ...@@ -42,21 +48,22 @@ class MMFormatter(logging.Formatter):
self.debug_format = (f'%(asctime)s - %(name)s - {debug_prefix} - %(' self.debug_format = (f'%(asctime)s - %(name)s - {debug_prefix} - %('
'message)s') 'message)s')
def _get_prefix(self, level: str, color: bool) -> str: def _get_prefix(self, level: str, color: bool, blink=False) -> str:
"""Get the prefix of the target log level. """Get the prefix of the target log level.
Args: Args:
level (str): log level. level (str): log level.
color (bool): Whether to get colorful prefix. color (bool): Whether to get colorful prefix.
blink (bool): Whether the prefix will blink.
Returns: Returns:
str: The plain or colorful prefix. str: The plain or colorful prefix.
""" """
if color: if color:
prefix = colored( attrs = ['underline']
level, if blink:
self._color_mapping[level], attrs.append('blink')
attrs=['blink', 'underline']) prefix = colored(level, self._color_mapping[level], attrs=attrs)
else: else:
prefix = level prefix = level
return prefix return prefix
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment