-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
35 lines (28 loc) · 905 Bytes
/
main.py
File metadata and controls
35 lines (28 loc) · 905 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
32
33
34
35
import atexit
import json
import logging.config
import logging.handlers
logger = logging.getLogger("logger")
def setup_logging():
config_file = "logging_config.json"
with open(config_file, "r") as file:
config = json.load(file)
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()
logger.debug("This is a debug message")
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.error("This is an error message")
logger.critical("This is a critical message")
try:
x = 1 / 0
except ZeroDivisionError:
logger.exception("You can't divide by zero")
return
if __name__ == "__main__":
main()