From ffac42f9e5d1d3ebac690f29f0354b06acb961c8 Mon Sep 17 00:00:00 2001 From: Alexander Minges Date: Tue, 10 Feb 2026 14:12:45 +0100 Subject: [PATCH] refactor(matrix): replace logging depth magic number --- nanobot/channels/matrix.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nanobot/channels/matrix.py b/nanobot/channels/matrix.py index d73a849..63a07e0 100644 --- a/nanobot/channels/matrix.py +++ b/nanobot/channels/matrix.py @@ -18,6 +18,8 @@ from nanobot.bus.events import OutboundMessage from nanobot.channels.base import BaseChannel from nanobot.config.loader import get_data_dir +LOGGING_STACK_BASE_DEPTH = 2 + class _NioLoguruHandler(logging.Handler): """Route stdlib logging records from matrix-nio into Loguru output.""" @@ -29,7 +31,8 @@ class _NioLoguruHandler(logging.Handler): level = record.levelno frame = logging.currentframe() - depth = 2 + # Skip logging internals plus this handler frame when forwarding to Loguru. + depth = LOGGING_STACK_BASE_DEPTH while frame and frame.f_code.co_filename == logging.__file__: frame = frame.f_back depth += 1