From a18b8851f2a5e1441770b796f0340c4542f31c5a Mon Sep 17 00:00:00 2001 From: Nederer Dmitriy Date: Tue, 17 Jun 2025 14:43:45 +0300 Subject: [PATCH] Added external logging --- microbootstrap/instruments/logging_instrument.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/microbootstrap/instruments/logging_instrument.py b/microbootstrap/instruments/logging_instrument.py index 4335e39..c41f04a 100644 --- a/microbootstrap/instruments/logging_instrument.py +++ b/microbootstrap/instruments/logging_instrument.py @@ -150,10 +150,14 @@ def bootstrap(self) -> None: for unset_handlers_logger in self.instrument_config.logging_unset_handlers: logging.getLogger(unset_handlers_logger).handlers = [] + stream_handler: typing.Final = logging.StreamHandler() + root_logger: typing.Final = logging.getLogger() + *foreign_pre_chain, renderer = structlog.get_config()["processors"] structlog.configure( processors=[ *DEFAULT_STRUCTLOG_PROCESSORS, *self.instrument_config.logging_extra_processors, + *foreign_pre_chain, DEFAULT_STRUCTLOG_FORMATTER_PROCESSOR, ], context_class=dict, @@ -165,6 +169,17 @@ def bootstrap(self) -> None: wrapper_class=structlog.stdlib.BoundLogger, cache_logger_on_first_use=True, ) + stream_handler.setFormatter( + structlog.stdlib.ProcessorFormatter( + foreign_pre_chain=[ + *foreign_pre_chain, + structlog.stdlib.ProcessorFormatter.remove_processors_meta, + ], + processors=[renderer], + logger=root_logger, + ) + ) + root_logger.addHandler(stream_handler) @classmethod def get_config_type(cls) -> type[LoggingConfig]: