-
Notifications
You must be signed in to change notification settings - Fork 206
/
main.py
37 lines (29 loc) · 960 Bytes
/
main.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
import atexit
import json
import logging.config
import logging.handlers
import pathlib
logger = logging.getLogger("my_app") # __name__ is a common choice
def setup_logging():
config_file = pathlib.Path("logging_configs/2-stderr-json-file.json")
with open(config_file) as f_in:
config = json.load(f_in)
logging.config.dictConfig(config)
queue_handler = logging.getHandlerByName("queue_handler")
if queue_handler is not None:
queue_handler.listener.start()
atexit.register(queue_handler.listener.stop)
def main():
setup_logging()
logging.basicConfig(level="INFO")
logger.debug("debug message", extra={"x": "hello"})
logger.info("info message")
logger.warning("warning message")
logger.error("error message")
logger.critical("critical message")
try:
1 / 0
except ZeroDivisionError:
logger.exception("exception message")
if __name__ == "__main__":
main()