diff --git a/lite_bootstrap/instruments/logging_instrument.py b/lite_bootstrap/instruments/logging_instrument.py index e73924f..7f84321 100644 --- a/lite_bootstrap/instruments/logging_instrument.py +++ b/lite_bootstrap/instruments/logging_instrument.py @@ -13,6 +13,7 @@ if import_checker.is_structlog_installed: + import orjson import structlog @@ -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): @@ -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( diff --git a/pyproject.toml b/pyproject.toml index 1461899..acea905 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ otl = [ ] logging = [ "structlog", + "orjson", ] free-all = [ "lite-bootstrap[sentry,otl,logging]",