MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / _ColorfulFormatter

Class _ColorfulFormatter

util/logger.py:8–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6
7
8class _ColorfulFormatter(logging.Formatter):
9 def __init__(self, *args, **kwargs):
10 self._root_name = kwargs.pop('root_name') + '.'
11 self._abbrev_name = kwargs.pop('abbrev_name', '')
12 if len(self._abbrev_name):
13 self._abbrev_name = self._abbrev_name + '.'
14 super(_ColorfulFormatter, self).__init__(*args, **kwargs)
15
16 def formatMessage(self, record):
17 record.name = record.name.replace(self._root_name, self._abbrev_name)
18 log = super(_ColorfulFormatter, self).formatMessage(record)
19 if record.levelno == logging.WARNING:
20 prefix = colored('WARNING', 'red', attrs=['blink'])
21 elif record.levelno == logging.ERROR or record.levelno == logging.CRITICAL:
22 prefix = colored('ERROR', 'red', attrs=['blink', 'underline'])
23 else:
24 return log
25 return prefix + ' ' + log
26
27
28# so that calling setup_logger multiple times won't add many handlers

Callers 1

setup_loggerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected