File tree Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Expand file tree Collapse file tree 1 file changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,14 @@ class IndentFormatter(logging.Formatter):
13
13
indentation using ``'\t '`` characters.
14
14
"""
15
15
16
+ color_map = {
17
+ logging .CRITICAL : 31 , # red
18
+ logging .ERROR : 31 , # red
19
+ logging .WARNING : 33 , # yellow
20
+ SUCCESS : 32 , # green
21
+ logging .INFO : 34 , # blue
22
+ }
23
+
16
24
@staticmethod
17
25
def identify_cut (filenames ):
18
26
"""
@@ -51,11 +59,26 @@ def update_format(self, record):
51
59
"""
52
60
53
61
prefix = "\u001b ["
62
+ color = f"{ self .color_map [record .levelno ]} m"
54
63
bold = "1m"
55
64
reset = "0m"
56
- self ._style ._fmt = (
57
- "::%(levelname)-8s file=%(filename)-20s,line=%(lineno)-4d::"
58
- "%(asctime)s │ "
65
+ if record .levelname in ["WARNING" , "ERROR" ]:
66
+ self ._style ._fmt = (
67
+ "::%(levelname)s file=%(filename)s,line=%(lineno)d::"
68
+ "%(asctime)s │ "
69
+ )
70
+ elif record .levelname == "DEBUG" :
71
+ self ._style ._fmt = (
72
+ "::%(levelname)s::"
73
+ "%(asctime)s │ "
74
+ )
75
+ else :
76
+ self ._style ._fmt = (
77
+ "%(asctime)s │ "
78
+ f"{ prefix } { color } %(levelname)-8s{ prefix } { reset } │ "
79
+ )
80
+
81
+ self ._style ._fmt += (
59
82
f"%(indent)s{ prefix } { bold } %(function)s{ prefix } { reset } : "
60
83
"%(message)s"
61
84
)
You can’t perform that action at this time.
0 commit comments