Should the file be named colorize_logging.py (or colorize_logs.py)?
<details><summary>nit, <code>black</code> linter suggestions</summary><p>
@@ -2,19 +2,23 @@
# Copyright (c) 2022 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
-'''
+"""
Colorize log output
Usage: ./bitcoind | contrib/devtools/colorize.py
-'''
+"""
import re
colors = ("cyan", "red", "blue", "green", "magenta")
color_codes = ("\033[36m", "\033[31m", "\033[34m", "\033[32m", "\033[35m")
+
def colorize(text):
# Colorize groups of brackets
for i, match in enumerate(re.finditer(r"\[.*?\]", text)):
- text = text.replace(match.group(0), color_codes[(i + 1) % len(colors)] + match.group(0) + "\033[0m")
+ text = text.replace(
+ match.group(0),
+ color_codes[(i + 1) % len(colors)] + match.group(0) + "\033[0m",
+ )
# Colorize date
date = re.search(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z", text)
@@ -23,8 +27,10 @@ def colorize(text):
return text
+
if __name__ == "__main__":
import sys
+
try:
for line in sys.stdin:
print(colorize(line), end="")
</p></details>