From dfea4471363c0904b784fb0e78b5d1b30085e27e Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Fri, 15 Mar 2024 21:28:09 +0100 Subject: [PATCH] logging: capture warnings emitted using warnings.warn() By default, warnings emitted by warnings.warn() will show on stderr. For a TUI application, this is a problem because they will be displayed over the UI and create visual glitches. For parts of the UI that are regularly redrawn, the text of the warning will eventually go away (sometimes instantly, making the warning impossible to read). For parts of the screen that are *not* regularly redrawn, the text of the warning will stay until the user sends a Ctrl-L sequence. We now make use of logging.captureWarnings() to redirect the warnings to the log files. This prevents the UI glitches and if any warning is emitted, we can actually find it in the logs. Signed-off-by: Olivier Gayot --- subiquity/cmd/server.py | 1 + subiquity/cmd/tui.py | 1 + 2 files changed, 2 insertions(+) diff --git a/subiquity/cmd/server.py b/subiquity/cmd/server.py index 49ff8ac0..8e4bd546 100644 --- a/subiquity/cmd/server.py +++ b/subiquity/cmd/server.py @@ -193,6 +193,7 @@ def main(): logfiles = setup_logger(dir=logdir, base="subiquity-server") + logging.captureWarnings(True) logger = logging.getLogger("subiquity") revision = os.environ.get("SNAP_REVISION", "unknown") version = os.environ.get("SNAP_VERSION", "unknown") diff --git a/subiquity/cmd/tui.py b/subiquity/cmd/tui.py index b6933bf8..740d69aa 100755 --- a/subiquity/cmd/tui.py +++ b/subiquity/cmd/tui.py @@ -124,6 +124,7 @@ def main(): logdir = opts.output_base logfiles = setup_logger(dir=logdir, base="subiquity-client") + logging.captureWarnings(True) logger = logging.getLogger("subiquity") version = os.environ.get("SNAP_REVISION", "unknown") snap = os.environ.get("SNAP", "unknown")