From 53b8ce3fb5675d2b0ce1d79b2643efb7f3b81c9a Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Fri, 12 Dec 2025 13:05:56 +0300 Subject: [PATCH 1/3] Enable logging in debug mode and improve log message format --- microbootstrap/instruments/logging_instrument.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/microbootstrap/instruments/logging_instrument.py b/microbootstrap/instruments/logging_instrument.py index 1426aa3..48f4cc2 100644 --- a/microbootstrap/instruments/logging_instrument.py +++ b/microbootstrap/instruments/logging_instrument.py @@ -47,6 +47,7 @@ def fill_log_message( http_version: typing.Final = request.scope["http_version"] log_on_correct_level: typing.Final = getattr(access_logger, log_level) log_on_correct_level( + f"{http_method} {url_with_query}", http={ "url": url_with_query, "status_code": status_code, @@ -146,10 +147,10 @@ def remove_trailing_slashes_from_logging_exclude_endpoints(self) -> typing_exten class LoggingInstrument(Instrument[LoggingConfig]): instrument_name = "Logging" - ready_condition = "Works only in non-debug mode" + ready_condition = "Always ready" def is_ready(self) -> bool: - return not self.instrument_config.service_debug + return True def teardown(self) -> None: structlog.reset_defaults() @@ -159,6 +160,8 @@ def _unset_handlers(self) -> None: logging.getLogger(unset_handlers_logger).handlers = [] def _configure_structlog_loggers(self) -> None: + if self.instrument_config.service_debug: + return structlog.configure( processors=[ structlog.stdlib.filter_by_level, @@ -188,6 +191,10 @@ def _configure_foreign_loggers(self) -> None: ], logger=root_logger, ) + if not self.instrument_config.service_debug + else structlog.stdlib.ProcessorFormatter( + processors=structlog.get_config()["processors"], logger=root_logger + ) ) root_logger.addHandler(stream_handler) root_logger.setLevel(self.instrument_config.logging_log_level) From 34f95a1ddd8f6c6ed58a1b39b1baadeca8ccbf74 Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Fri, 12 Dec 2025 13:11:47 +0300 Subject: [PATCH 2/3] Fix logging instrument processor configuration for debug mode --- microbootstrap/instruments/logging_instrument.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/microbootstrap/instruments/logging_instrument.py b/microbootstrap/instruments/logging_instrument.py index 48f4cc2..5ca6d23 100644 --- a/microbootstrap/instruments/logging_instrument.py +++ b/microbootstrap/instruments/logging_instrument.py @@ -193,7 +193,12 @@ def _configure_foreign_loggers(self) -> None: ) if not self.instrument_config.service_debug else structlog.stdlib.ProcessorFormatter( - processors=structlog.get_config()["processors"], logger=root_logger + foreign_pre_chain=structlog.get_config()["processors"][:-1], + processors=[ + structlog.stdlib.ProcessorFormatter.remove_processors_meta, + structlog.get_config()["processors"][-1], + ], + logger=root_logger, ) ) root_logger.addHandler(stream_handler) From 81d3fc4319ec726a2a704848e71a3b7e52a816ef Mon Sep 17 00:00:00 2001 From: Lev Vereshchagin Date: Fri, 12 Dec 2025 13:16:15 +0300 Subject: [PATCH 3/3] Fix logging instrument configuration logic --- microbootstrap/instruments/logging_instrument.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/microbootstrap/instruments/logging_instrument.py b/microbootstrap/instruments/logging_instrument.py index 5ca6d23..07839a2 100644 --- a/microbootstrap/instruments/logging_instrument.py +++ b/microbootstrap/instruments/logging_instrument.py @@ -184,19 +184,19 @@ def _configure_foreign_loggers(self) -> None: stream_handler: typing.Final = logging.StreamHandler(sys.stdout) stream_handler.setFormatter( structlog.stdlib.ProcessorFormatter( - foreign_pre_chain=STRUCTLOG_PRE_CHAIN_PROCESSORS, + foreign_pre_chain=structlog.get_config()["processors"][:-1], processors=[ structlog.stdlib.ProcessorFormatter.remove_processors_meta, - STRUCTLOG_FORMATTER_PROCESSOR, + structlog.get_config()["processors"][-1], ], logger=root_logger, ) - if not self.instrument_config.service_debug + if self.instrument_config.service_debug else structlog.stdlib.ProcessorFormatter( - foreign_pre_chain=structlog.get_config()["processors"][:-1], + foreign_pre_chain=STRUCTLOG_PRE_CHAIN_PROCESSORS, processors=[ structlog.stdlib.ProcessorFormatter.remove_processors_meta, - structlog.get_config()["processors"][-1], + STRUCTLOG_FORMATTER_PROCESSOR, ], logger=root_logger, )