forked from Gnomeball/SwackQuote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.py
59 lines (49 loc) · 1.65 KB
/
logs.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
58
59
"""
Quick but reliable logging wrapper that will rotate log files cleanly in our desired formatting.
Only imported by `bot.py`, which calls `init()`, and from then on everything is ready to use.
"""
import logging
import logging.config
import logging.handlers
from pathlib import Path
def init() -> None:
"""Configure `logging` with our handlers of choice."""
OUTLOG.touch()
ERRLOG.touch()
DBGLOG.touch()
logging.config.dictConfig(LOG_CONFIG)
OUTLOG = Path("out.log")
"Where INFO level logging goes."
ERRLOG = Path("err.log")
"Where ERROR level logging goes."
DBGLOG = Path("dbg.log")
"Where DEBUG level logging goes (when used)."
FILE_CONFIG = {"formatter": "fmt", "maxBytes": 10**6, "backupCount": 5}
"We limit logs to 1MB, and rotate through up to 5 at a time."
LOG_CONFIG = {
"version": 1,
"disable_existing_loggers": True,
"formatters": {"fmt": {"format": "[{asctime}: {name} {levelname}]: {message}", "style": "{"}},
"handlers": {
"outfile": {
"class": "logging.handlers.RotatingFileHandler",
"level": "INFO",
"filename": OUTLOG,
**FILE_CONFIG,
},
"errfile": {
"class": "logging.handlers.RotatingFileHandler",
"level": "ERROR",
"filename": ERRLOG,
**FILE_CONFIG,
},
"debugfile": {
"class": "logging.handlers.RotatingFileHandler",
"level": "DEBUG",
"filename": DBGLOG,
**FILE_CONFIG,
},
},
"root": {"level": "INFO", "handlers": ["outfile", "errfile", "debugfile"]},
}
"We have INFO, ERROR, and DEBUG logging setup, with our formatting."