-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlog.py
57 lines (42 loc) · 1.17 KB
/
log.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import logging
import os
import warnings
from datetime import datetime
from config import config
warnings.filterwarnings("ignore")
from rich.traceback import install
install(show_locals=True)
rootlogger = logging.getLogger()
for handler in rootlogger.handlers.copy():
try:
rootlogger.removeHandler(handler)
except ValueError:
pass
rootlogger.addHandler(logging.NullHandler())
log = logging.getLogger(config.name)
log.propagate = False
log.setLevel(logging.DEBUG)
if not os.path.exists("logs"):
os.makedirs("logs")
class FlushFilter(logging.Filter):
def filter(self, record):
return not hasattr(record, "flush")
flush_filter = FlushFilter()
handler = logging.FileHandler(
os.path.join(
"logs",
f"{datetime.now().strftime('%Y%m%d-%H%M%S')}-obs_watcher.log",
),
encoding="utf-8",
)
handler.setLevel(logging.DEBUG)
handler.addFilter(flush_filter)
one_file_handler = logging.FileHandler(
mode="a",
filename=os.path.join("logs", "_obs_watcher.log"),
encoding="utf-8",
)
one_file_handler.setLevel(logging.DEBUG)
one_file_handler.addFilter(flush_filter)
log.addHandler(handler)
log.addHandler(one_file_handler)