33
44from colored import fg , attr
55from copy import copy
6+ from friendlylog .constants import (
7+ DEBUG ,
8+ INFO ,
9+ WARNING ,
10+ ERROR ,
11+ CRITICAL ,
12+
13+ LOG_LEVEL_LIST
14+ )
615from friendlylog .utils import do_not_propagate
716
817
918# Where the logs should be sent.
1019_STREAM = sys .stdout
1120
21+
1222class _ColoredFormatter (logging .Formatter ):
1323
1424 def __init__ (self , * args , ** kwargs ):
1525 super (_ColoredFormatter , self ).__init__ (* args , ** kwargs )
1626
1727 @staticmethod
1828 def _colorize (msg , loglevel ):
19- DEBUG = "debug"
20- INFO = "info"
21- WARNING = "warning"
22- ERROR = "error"
23- CRITICAL = "critical"
24-
2529 loglevel = str (loglevel ).lower ()
26- if loglevel not in [ DEBUG , INFO , WARNING , ERROR , CRITICAL ] :
30+ if loglevel not in LOG_LEVEL_LIST :
2731 raise RuntimeError ("{} should be oneof {}." .format (
28- loglevel , [ DEBUG , INFO , WARNING , ERROR , CRITICAL ] )) # pragma: no cover
32+ loglevel , LOG_LEVEL_LIST )) # pragma: no cover
2933 msg = str (loglevel ).upper () + ": " + str (msg )
3034
3135 if loglevel == DEBUG :
@@ -37,7 +41,7 @@ def _colorize(msg, loglevel):
3741 if loglevel == ERROR :
3842 return "{}{}{}{}{}" .format (fg (202 ), attr (1 ), msg , attr (21 ), attr (0 )) # noqa: E501
3943 if loglevel == CRITICAL :
40- return "{}{}{}{}{}" .format (fg (196 ), attr (1 ), msg , attr (21 ), attr (0 ))
44+ return "{}{}{}{}{}" .format (fg (196 ), attr (1 ), msg , attr (21 ), attr (0 )) # noqa: E501
4145
4246 def format (self , record ):
4347 record = copy (record )
0 commit comments