Should the file be named colorize_logging.py
(or colorize_logs.py
)?
0@@ -2,19 +2,23 @@
1 # Copyright (c) 2022 The Bitcoin Core developers
2 # Distributed under the MIT software license, see the accompanying
3 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
4-'''
5+"""
6 Colorize log output
7 Usage: ./bitcoind | contrib/devtools/colorize.py
8-'''
9+"""
10 import re
11
12 colors = ("cyan", "red", "blue", "green", "magenta")
13 color_codes = ("\033[36m", "\033[31m", "\033[34m", "\033[32m", "\033[35m")
14
15+
16 def colorize(text):
17 # Colorize groups of brackets
18 for i, match in enumerate(re.finditer(r"\[.*?\]", text)):
19- text = text.replace(match.group(0), color_codes[(i + 1) % len(colors)] + match.group(0) + "\033[0m")
20+ text = text.replace(
21+ match.group(0),
22+ color_codes[(i + 1) % len(colors)] + match.group(0) + "\033[0m",
23+ )
24
25 # Colorize date
26 date = re.search(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z", text)
27@@ -23,8 +27,10 @@ def colorize(text):
28
29 return text
30
31+
32 if __name__ == "__main__":
33 import sys
34+
35 try:
36 for line in sys.stdin:
37 print(colorize(line), end="")