-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlog_setup.py
More file actions
31 lines (24 loc) · 933 Bytes
/
Copy pathlog_setup.py
File metadata and controls
31 lines (24 loc) · 933 Bytes
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
"""Named-logger setup per Victron mvader recommendation.
Critical: NEVER call logging.basicConfig() - that configures the root logger
and turns every dependency (urllib3, dbus, ...) verbose. Use a named logger
attached to a StreamHandler. stdout/stderr is captured by daemontools and
piped to multilog (see service/log/run).
"""
import logging
import sys
LOGGER_NAME = "dbus-evcc-multi"
def configure_logging(debug: bool = False) -> logging.Logger:
logger = logging.getLogger(LOGGER_NAME)
level = logging.DEBUG if debug else logging.INFO
if logger.handlers:
logger.setLevel(level)
return logger
logger.setLevel(level)
logger.propagate = False
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(logging.Formatter(
fmt="%(asctime)s %(levelname)s %(name)s %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
))
logger.addHandler(handler)
return logger