11__author__ = "desultory"
2- __version__ = "3.0 .0"
2+ __version__ = "3.1 .0"
33
44from logging import Formatter
55
6- from zenlib .util import colorize
7-
86
97class ColorLognameFormatter (Formatter ):
108 """A logging formatter which colors the levelname of the log message.
119 Uses the zenlib.util.colorize function to color the levelname.
1210 Normal levelnames are padded to the length of the longest levelname."""
1311
1412 level_colors = {
15- "DEBUG" : {"color" : "white" },
13+ "DEBUG" : {"color" : "white" , "bright" : True },
1614 "INFO" : {"color" : "blue" },
1715 "WARNING" : {"color" : "yellow" },
1816 "ERROR" : {"color" : "red" , "bold" : True },
@@ -21,11 +19,13 @@ class ColorLognameFormatter(Formatter):
2119
2220 def __init__ (self , fmt = "%(levelname)s | %(message)s" , * args , ** kwargs ):
2321 super ().__init__ (fmt , * args , ** kwargs )
24- self .level_str_width = max (len (name ) for name in self .level_colors ) - 1
22+ self .level_str_width = max (len (name ) for name in self .level_colors )
2523
2624 def format (self , record ):
2725 # When calling format, replace the levelname with a colored version
2826 # Note: the string size is greatly increased because of the color codes
27+ from zenlib .util import colorize
28+
2929 old_levelname = record .levelname
3030 color_info = self .level_colors .get (record .levelname , {"color" : "white" })
3131 record .levelname = colorize (record .levelname .ljust (self .level_str_width ), ** color_info )
0 commit comments