From 23c8893ebcfed1900e44c6c4ad218c7483f8e72d Mon Sep 17 00:00:00 2001 From: MarcusStill <69536339+MarcusStill@users.noreply.github.com> Date: Wed, 9 Sep 2026 03:21:11 +0000 Subject: [PATCH] Fix missing and delayed logs on exit and exceptions Added `buffering=1` to the loguru configuration to enable immediate line-by-line writing to the log file. Added `logger.complete()` before application exit and in the uncaught exception handler to ensure that asynchronous logs are completely flushed out before the program terminates. Also added loading of `log_level` from configuration as required. --- main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c7f54d0..1fe38ab 100644 --- a/main.py +++ b/main.py @@ -55,7 +55,8 @@ system = System() config_data = system.config -logger.add(system.log_file, rotation="1 MB", enqueue=True) +log_level = config_data.get("log_level") or "DEBUG" +logger.add(system.log_file, rotation="1 MB", enqueue=True, buffering=1, level=log_level.upper()) def handle_uncaught_exception(exc_type, exc_value, exc_traceback): @@ -66,6 +67,7 @@ def handle_uncaught_exception(exc_type, exc_value, exc_traceback): logger.opt(exception=(exc_type, exc_value, exc_traceback)).error( "Неперехваченное исключение" ) + logger.complete() sys.excepthook = handle_uncaught_exception @@ -3559,4 +3561,6 @@ class Payment: auth = AuthForm() auth.show() auth.ui.label_9.setText(system.database) - sys.exit(app.exec()) + result = app.exec() + logger.complete() + sys.exit(result)