Skip to content

Commit 563c634

Browse files
authored
Merge pull request #79 from modern-python/feat/configurable-time-stamper
feat: make TimeStamper configurable in LoggingConfig
2 parents 65fcbd2 + 05241c1 commit 563c634

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

docs/introduction/configuration.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,18 @@ Additional parameters:
113113
- `logging_flush_level`
114114
- `logging_buffer_capacity`
115115
- `logging_extra_processors`
116-
- `logging_unset_handlers`.
116+
- `logging_unset_handlers`
117+
- `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:
118+
119+
```python
120+
import structlog
121+
from lite_bootstrap import FastAPIConfig
122+
123+
config = FastAPIConfig(
124+
service_debug=False,
125+
logging_time_stamper=structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S", utc=True),
126+
)
127+
```
117128

118129
### Structlog Litestar
119130

lite_bootstrap/instruments/logging_instrument.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class LoggingConfig(BaseConfig):
9595
logging_unset_handlers: list[str] = dataclasses.field(
9696
default_factory=list,
9797
)
98+
logging_time_stamper: "structlog.processors.TimeStamper | None" = None
9899

99100

100101
@dataclasses.dataclass(kw_only=True, slots=True, frozen=True)
@@ -110,7 +111,7 @@ def structlog_pre_chain_processors(self) -> list[typing.Any]:
110111
structlog.stdlib.add_logger_name,
111112
tracer_injection,
112113
structlog.stdlib.PositionalArgumentsFormatter(),
113-
structlog.processors.TimeStamper(fmt="%Y-%m-%d %H:%M:%S"),
114+
self.bootstrap_config.logging_time_stamper or structlog.processors.TimeStamper(fmt="iso"),
114115
structlog.processors.StackInfoRenderer(),
115116
structlog.processors.format_exc_info,
116117
structlog.processors.UnicodeDecoder(),

0 commit comments

Comments
 (0)