From 855839c8b532e53477ea186d633d8784118fdf92 Mon Sep 17 00:00:00 2001 From: MarcusStill <69536339+MarcusStill@users.noreply.github.com> Date: Fri, 11 Sep 2026 03:37:50 +0000 Subject: [PATCH] Fix log buffering issues and add dynamic log level configuration - Enforce line-buffering on loguru file output by adding `buffering=1` to ensure logs are written to disk immediately rather than waiting for the buffer to fill. - Add an optional `log_level` setting in the `[OTHER]` section of `config.ini` to dynamically control verbosity in production without modifying source code (defaults to `DEBUG`). - Change PySide6 exit sequence from `sys.exit(app.exec())` to store exit code and explicitly quit, preventing issues with finalization hooks and log flushes not running correctly. --- main.py | 5 +++-- modules/config.py | 4 ++++ modules/system.py | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index c7f54d0..c851739 100644 --- a/main.py +++ b/main.py @@ -55,7 +55,7 @@ system = System() config_data = system.config -logger.add(system.log_file, rotation="1 MB", enqueue=True) +logger.add(system.log_file, rotation="1 MB", enqueue=True, buffering=1, level=system.log_level) def handle_uncaught_exception(exc_type, exc_value, exc_traceback): @@ -3559,4 +3559,5 @@ class Payment: auth = AuthForm() auth.show() auth.ui.label_9.setText(system.database) - sys.exit(app.exec()) + exit_code = app.exec() + sys.exit(exit_code) diff --git a/modules/config.py b/modules/config.py index 3cb0a17..9c0ca78 100644 --- a/modules/config.py +++ b/modules/config.py @@ -122,6 +122,10 @@ def load_config(self): ) config_data[key] = config.get(section, key) + if config.has_option("OTHER", "log_level"): + config_data["log_level"] = config.get("OTHER", "log_level") + else: + config_data["log_level"] = "DEBUG" return config_data except (NoSectionError, NoOptionError) as e: diff --git a/modules/system.py b/modules/system.py index 34c8fdf..55e0abc 100644 --- a/modules/system.py +++ b/modules/system.py @@ -38,6 +38,7 @@ def __init__(self): self.user = self.config.get("user") self.software_version = self.config.get("version") self.log_file = self.config.get("log_file") + self.log_level = self.config.get("log_level").upper() # Информация о РМ self.kol_pc = int(self.config.get("kol")) self.pcs = self.config.pcs # список рабочих станций