Skip to content

Commit 0cce8ca

Browse files
committed
Change Formatting for Log Records
1. Reverted back to original color coding 2. Separate formatting for GitHub workflow commands - `error`, `warning` and `debug`
1 parent e6239cd commit 0cce8ca

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

normalize_repos/log.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ class IndentFormatter(logging.Formatter):
1313
indentation using ``'\t'`` characters.
1414
"""
1515

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+
1624
@staticmethod
1725
def identify_cut(filenames):
1826
"""
@@ -51,11 +59,26 @@ def update_format(self, record):
5159
"""
5260

5361
prefix = "\u001b["
62+
color = f"{self.color_map[record.levelno]}m"
5463
bold = "1m"
5564
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 += (
5982
f"%(indent)s{prefix}{bold}%(function)s{prefix}{reset}: "
6083
"%(message)s"
6184
)

0 commit comments

Comments
 (0)