MCPcopy
hub / github.com/InternLM/lmdeploy / ColorFormatter

Class ColorFormatter

lmdeploy/utils.py:60–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58
59
60class ColorFormatter(logging.Formatter):
61
62 _LEVELNAME_COLOR_MAP = dict(CRITICAL=_ASNI_COLOR.BRIGHT_RED,
63 ERROR=_ASNI_COLOR.RED,
64 WARN=_ASNI_COLOR.YELLOW,
65 WARNING=_ASNI_COLOR.YELLOW,
66 REQUEST=_ASNI_COLOR.WHITE,
67 INFO=_ASNI_COLOR.WHITE,
68 DEBUG=_ASNI_COLOR.GREEN)
69
70 _RESET_COLOR = '\033[0m'
71
72 def format(self, record: LogRecord):
73 """format."""
74 if not can_colorize():
75 # windows does not support ASNI color
76 return super().format(record)
77 levelname = record.levelname
78 level_color = self._LEVELNAME_COLOR_MAP.get(levelname, self._RESET_COLOR)
79 levelname = f'{level_color}{levelname}{self._RESET_COLOR}'
80 record.levelname = levelname
81 return super().format(record)
82
83
84class FilterDuplicateWarning(logging.Filter):

Callers 1

get_loggerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected