From 05241c13b41a938aeb3a73a3f399e329da49cbe9 Mon Sep 17 00:00:00 2001 From: Artur Shiriev Date: Thu, 30 Apr 2026 19:37:40 +0300 Subject: [PATCH] feat: make TimeStamper configurable in LoggingConfig --- docs/introduction/configuration.md | 13 ++++++++++++- lite_bootstrap/instruments/logging_instrument.py | 3 ++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/docs/introduction/configuration.md b/docs/introduction/configuration.md index 587d77f..f15d768 100644 --- a/docs/introduction/configuration.md +++ b/docs/introduction/configuration.md @@ -113,7 +113,18 @@ Additional parameters: - `logging_flush_level` - `logging_buffer_capacity` - `logging_extra_processors` -- `logging_unset_handlers`. +- `logging_unset_handlers` +- `logging_time_stamper` - a `structlog.processors.TimeStamper` instance controlling timestamp format (default: `TimeStamper(fmt="iso")`). Pass a custom instance to change the format or enable UTC: + +```python +import structlog +from lite_bootstrap import FastAPIConfig + +config = FastAPIConfig( + service_debug=False, + logging_time_stamper=structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S", utc=True), +) +``` ### Structlog Litestar diff --git a/lite_bootstrap/instruments/logging_instrument.py b/lite_bootstrap/instruments/logging_instrument.py index 25844bf..52aa338 100644 --- a/lite_bootstrap/instruments/logging_instrument.py +++ b/lite_bootstrap/instruments/logging_instrument.py @@ -95,6 +95,7 @@ class LoggingConfig(BaseConfig): logging_unset_handlers: list[str] = dataclasses.field( default_factory=list, ) + logging_time_stamper: "structlog.processors.TimeStamper | None" = None @dataclasses.dataclass(kw_only=True, slots=True, frozen=True) @@ -110,7 +111,7 @@ def structlog_pre_chain_processors(self) -> list[typing.Any]: structlog.stdlib.add_logger_name, tracer_injection, structlog.stdlib.PositionalArgumentsFormatter(), - structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S"), + self.bootstrap_config.logging_time_stamper or structlog.processors.TimeStamper(fmt="iso"), structlog.processors.StackInfoRenderer(), structlog.processors.format_exc_info, structlog.processors.UnicodeDecoder(),