-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.py
More file actions
77 lines (68 loc) · 1.89 KB
/
logger.py
File metadata and controls
77 lines (68 loc) · 1.89 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Logger module where other modules can import the logger to log messages to the
console in a consistent format
"""
import os
from logging import config, getLogger
server_logger = getLogger("daqserver")
web_logger = getLogger("daqweb")
db_logger = getLogger("daqdb")
streaming_logger = getLogger("daqstreaming")
def setup_logging():
LOG_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()
EXTRA_LOGGERS = os.getenv("EXTRA_LOGGERS", "")
_extra_logger_names = [
name.strip() for name in EXTRA_LOGGERS.split(",") if name.strip()
]
_loggers_config = {
"daqserver": {
"level": LOG_LEVEL,
"handlers": ["rich"],
"propagate": False,
},
"daqweb": {
"level": LOG_LEVEL,
"handlers": ["rich"],
"propagate": False,
},
"daqdb": {
"level": LOG_LEVEL,
"handlers": ["rich"],
"propagate": False,
},
"daqstreaming": {
"level": LOG_LEVEL,
"handlers": ["rich"],
"propagate": False,
},
"root": {
"level": "WARNING",
"handlers": ["rich"],
},
}
for name in _extra_logger_names:
_loggers_config[name] = {
"level": LOG_LEVEL,
"handlers": ["rich"],
"propagate": False,
}
LOGGING_CONFIG = {
"version": 1,
"disable_existing_loggers": False,
"formatters": {
"rich": {
"format": "%(message)s",
},
},
"handlers": {
"rich": {
"class": "rich.logging.RichHandler",
"level": "DEBUG",
"formatter": "rich",
"rich_tracebacks": True,
"markup": True,
},
},
"loggers": _loggers_config,
}
config.dictConfig(LOGGING_CONFIG)