-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathobjects.py
More file actions
42 lines (36 loc) · 1.26 KB
/
Copy pathobjects.py
File metadata and controls
42 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from logging import Formatter, LogRecord
class LogFormatter(Formatter):
def __init__(self, use_ansi: bool = True):
self.use_ansi = use_ansi
self.codes = {
"WARN": "\033[33m",
"CRITICAL": "\033[95m",
"ERROR": "\033[31m",
"DBUG": "\033[34;1m",
"RESET": "\033[0m",
"INFO": "\033[1;32m",
"START" : "\033[1;30m"
}
if use_ansi:
super().__init__(
fmt=self.codes["START"] + '[{asctime} {name}/{levelname}]:' + self.codes["RESET"] + ' {message}',
datefmt=r"%Y/%m/%d %H:%M:%S",
style="{"
)
else:
super().__init__(
fmt="[{asctime} {name}/{levelname}]: {message}",
datefmt=r"%Y/%m/%d %H:%M:%S",
style="{"
)
def format(self, r: LogRecord):
rename_lvls = {
"WARNING" : "WARN",
"DEBUG" : "DBUG"
}
new_name = rename_lvls.get(r.levelname)
if new_name is not None:
r.levelname = new_name
if r.levelname in self.codes and self.use_ansi:
r.msg = self.codes[r.levelname] + str(r.msg) + self.codes["RESET"]
return super().format(r)