-
-
Notifications
You must be signed in to change notification settings - Fork 324
/
Copy pathlogging.py
43 lines (36 loc) · 1.02 KB
/
logging.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
import logging
import sys
from logging.config import dictConfig
from .config import IDOM_DEBUG_MODE
dictConfig(
{
"version": 1,
"disable_existing_loggers": False,
"loggers": {
"idom": {"handlers": ["console"]},
},
"handlers": {
"console": {
"class": "logging.StreamHandler",
"formatter": "generic",
"stream": sys.stdout,
}
},
"formatters": {
"generic": {
"format": "%(asctime)s | %(log_color)s%(levelname)s%(reset)s | %(message)s",
"datefmt": r"%Y-%m-%dT%H:%M:%S%z",
"class": "colorlog.ColoredFormatter",
}
},
}
)
ROOT_LOGGER = logging.getLogger("idom")
"""IDOM's root logger instance"""
@IDOM_DEBUG_MODE.subscribe
def _set_debug_level(debug: bool) -> None:
if debug:
ROOT_LOGGER.setLevel("DEBUG")
ROOT_LOGGER.debug("IDOM is in debug mode")
else:
ROOT_LOGGER.setLevel("INFO")