Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lite_bootstrap/instruments/logging_instrument.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@


if import_checker.is_structlog_installed:
import orjson
import structlog


Expand Down Expand Up @@ -80,6 +81,9 @@ def __call__(self, *args: typing.Any) -> logging.Logger: # noqa: ANN401
logger.propagate = False
return logger

def _serialize_log_with_orjson_to_string(value: typing.Any, **kwargs: typing.Any) -> str: # noqa: ANN401
return orjson.dumps(value, **kwargs).decode()


@dataclasses.dataclass(kw_only=True, frozen=True)
class LoggingConfig(BaseConfig):
Expand Down Expand Up @@ -128,7 +132,7 @@ def _configure_structlog_loggers(self) -> None:
structlog.stdlib.filter_by_level,
*self.structlog_pre_chain_processors,
*self.bootstrap_config.logging_extra_processors,
structlog.processors.JSONRenderer(),
structlog.processors.JSONRenderer(serializer=_serialize_log_with_orjson_to_string),
],
context_class=dict,
logger_factory=MemoryLoggerFactory(
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ otl = [
]
logging = [
"structlog",
"orjson",
]
free-all = [
"lite-bootstrap[sentry,otl,logging]",
Expand Down
Loading