Spaces:
Sleeping
Sleeping
Commit ·
3d9683d
1
Parent(s): c88f60c
Add log_utils.py for reformating log messages
Browse files- log_utils.py +33 -0
log_utils.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Foreground colors
|
| 2 |
+
RED = '\033[31m'
|
| 3 |
+
GREEN = '\033[32m'
|
| 4 |
+
YELLOW = '\033[33m'
|
| 5 |
+
BLUE = '\033[34m'
|
| 6 |
+
MAGENTA = '\033[35m'
|
| 7 |
+
CYAN = '\033[36m'
|
| 8 |
+
WHITE = '\033[37m'
|
| 9 |
+
|
| 10 |
+
# Background color
|
| 11 |
+
BG_BLACK = '\033[40m'
|
| 12 |
+
BG_BLUE = '\033[44m'
|
| 13 |
+
|
| 14 |
+
# Reset code to return to default color
|
| 15 |
+
RESET = '\033[0m'
|
| 16 |
+
|
| 17 |
+
mapper = {
|
| 18 |
+
BG_BLACK+RED: "#dd0000",
|
| 19 |
+
BG_BLACK+GREEN: "#00dd00",
|
| 20 |
+
BG_BLACK+YELLOW: "#dddd00",
|
| 21 |
+
BG_BLACK+BLUE: "#0000ee",
|
| 22 |
+
BG_BLACK+MAGENTA: "#aa00dd",
|
| 23 |
+
BG_BLACK+CYAN: "#00dddd",
|
| 24 |
+
BG_BLACK+WHITE: "#87CEEB",
|
| 25 |
+
BG_BLUE+WHITE: "#ff7800"
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def reformat(message):
|
| 30 |
+
for key, value in mapper.items():
|
| 31 |
+
message = message.replace(key, f'<span style="color: {value}">')
|
| 32 |
+
message = message.replace(RESET, '</span>')
|
| 33 |
+
return message
|