Skip to content

Commit 06e5cd2

Browse files
authored
Make sure logs are string, not bytes (#112)
1 parent bc92ffc commit 06e5cd2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

microbootstrap/instruments/logging_instrument.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,15 @@ def tracer_injection(_: WrappedLogger, __: str, event_dict: EventDict) -> EventD
8282
structlog.processors.format_exc_info,
8383
structlog.processors.UnicodeDecoder(),
8484
]
85-
DEFAULT_STRUCTLOG_FORMATTER_PROCESSOR: typing.Final = structlog.processors.JSONRenderer(serializer=orjson.dumps)
85+
86+
87+
def _serialize_log_with_orjson_to_string(value: typing.Any, **kwargs: typing.Any) -> str: # noqa: ANN401
88+
return orjson.dumps(value, **kwargs).decode()
89+
90+
91+
DEFAULT_STRUCTLOG_FORMATTER_PROCESSOR: typing.Final = structlog.processors.JSONRenderer(
92+
serializer=_serialize_log_with_orjson_to_string
93+
)
8694

8795

8896
class MemoryLoggerFactory(structlog.stdlib.LoggerFactory):

0 commit comments

Comments
 (0)