From 7e4677a89f197e58e8d4918458199d6444da19f9 Mon Sep 17 00:00:00 2001 From: Mikhail Murzinov Date: Thu, 7 May 2026 15:32:46 +0300 Subject: [PATCH 1/2] add kwargs for timestamper processor in LoggingConfig --- 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 be4f81a..12c163e 100644 --- a/microbootstrap/instruments/logging_instrument.py +++ b/microbootstrap/instruments/logging_instrument.py @@ -78,7 +78,6 @@ def tracer_injection(_: WrappedLogger, __: str, event_dict: EventDict) -> EventD structlog.stdlib.add_logger_name, tracer_injection, structlog.stdlib.PositionalArgumentsFormatter(), - structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S"), structlog.processors.StackInfoRenderer(), structlog.processors.format_exc_info, structlog.processors.UnicodeDecoder(), @@ -149,6 +148,9 @@ class LoggingConfig(BaseInstrumentConfig): ) logging_exclude_endpoints: list[str] = pydantic.Field(default_factory=lambda: ["/health/", "/metrics"]) logging_turn_off_middleware: bool = False + logging_timestamper_exra_params: dict[str, typing.Any] = pydantic.Field( + default_factory=lambda: {"fmt": "%Y-%m-%d %H:%M:%S"} + ) @pydantic.model_validator(mode="after") def remove_trailing_slashes_from_logging_exclude_endpoints(self) -> typing_extensions.Self: @@ -172,6 +174,10 @@ def _unset_handlers(self) -> None: for unset_handlers_logger in self.instrument_config.logging_unset_handlers: logging.getLogger(unset_handlers_logger).handlers = [] + @property + def _timestamper_processor(self) -> structlog.processors.TimeStamper: + return structlog.processors.TimeStamper(**self.instrument_config.logging_timestamper_exra_params) + def _configure_structlog_loggers(self) -> None: if self.instrument_config.service_debug: structlog.configure( @@ -186,6 +192,7 @@ def _configure_structlog_loggers(self) -> None: processors=[ structlog.stdlib.filter_by_level, *STRUCTLOG_PRE_CHAIN_PROCESSORS, + self._timestamper_processor, *self.instrument_config.logging_extra_processors, STRUCTLOG_FORMATTER_PROCESSOR, ], @@ -213,7 +220,7 @@ def _configure_foreign_loggers(self) -> None: ) if self.instrument_config.service_debug else structlog.stdlib.ProcessorFormatter( - foreign_pre_chain=STRUCTLOG_PRE_CHAIN_PROCESSORS, + foreign_pre_chain=[*STRUCTLOG_PRE_CHAIN_PROCESSORS, self._timestamper_processor], processors=[ structlog.stdlib.ProcessorFormatter.remove_processors_meta, STRUCTLOG_FORMATTER_PROCESSOR, From 3e8c5024ca196d6ee919d2d3120e7ec980afc952 Mon Sep 17 00:00:00 2001 From: Mikhail Murzinov Date: Fri, 8 May 2026 11:23:09 +0300 Subject: [PATCH 2/2] chore: review fixes --- microbootstrap/instruments/logging_instrument.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/microbootstrap/instruments/logging_instrument.py b/microbootstrap/instruments/logging_instrument.py index 12c163e..2d72c09 100644 --- a/microbootstrap/instruments/logging_instrument.py +++ b/microbootstrap/instruments/logging_instrument.py @@ -148,7 +148,7 @@ class LoggingConfig(BaseInstrumentConfig): ) logging_exclude_endpoints: list[str] = pydantic.Field(default_factory=lambda: ["/health/", "/metrics"]) logging_turn_off_middleware: bool = False - logging_timestamper_exra_params: dict[str, typing.Any] = pydantic.Field( + logging_timestamper_extra_params: dict[str, typing.Any] = pydantic.Field( default_factory=lambda: {"fmt": "%Y-%m-%d %H:%M:%S"} ) @@ -176,7 +176,7 @@ def _unset_handlers(self) -> None: @property def _timestamper_processor(self) -> structlog.processors.TimeStamper: - return structlog.processors.TimeStamper(**self.instrument_config.logging_timestamper_exra_params) + return structlog.processors.TimeStamper(**self.instrument_config.logging_timestamper_extra_params) def _configure_structlog_loggers(self) -> None: if self.instrument_config.service_debug: