From 7dea3863aac0ec1fe0dbc6d5c86a218d8aed5090 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Sun, 2 Mar 2025 20:28:37 +0100 Subject: [PATCH] feat(script): Log into queue --- logging_configs/config.json | 11 +++++++++-- main.py | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/logging_configs/config.json b/logging_configs/config.json index ee8ba3d..df10412 100644 --- a/logging_configs/config.json +++ b/logging_configs/config.json @@ -36,13 +36,20 @@ "formatter": "json", "maxBytes": 10000, "backupCount": 3 + }, + "queue_handler": { + "class": "logging.handlers.QueueHandler", + "handlers": [ + "rich", + "file" + ], + "respect_handler_level": true } }, "loggers": { "root": { "handlers": [ - "rich", - "file" + "queue_handler" ], "level": "DEBUG" } diff --git a/main.py b/main.py index cd274ea..2fa71d3 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ # import gnupg +import atexit import json import logging.config import pathlib @@ -12,6 +13,10 @@ def setup_logging(): with open(config_file, "r") as config_file: config = json.load(config_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():