When customizing StructLoggingConfig
with structlog.processors.JSONRenderer
processor, it is convenient to use default_json_serializer
.
However the function is currently not in __all__
, causing linting errors.
A quick solution would be to add it to module's __all__
, but maybe we can re-use encode_json
?
Here's an example of using structlog.processors.JSONRenderer
.
import structlog
from litestar import Litestar
from litestar import get
from litestar.logging import StructLoggingConfig
from litestar.logging.config import default_json_serializer
from litestar.plugins.structlog import StructlogConfig
from litestar.plugins.structlog import StructlogPlugin
logger = structlog.get_logger(__name__)
@get(path="/health", sync_to_thread=False)
def hello() -> dict:
logger.info("Hello World!")
return {"hello": "world"}
app = Litestar(
route_handlers=[hello],
plugins=[
StructlogPlugin(
config=StructlogConfig(
structlog_logging_config=StructLoggingConfig(
processors=[
structlog.processors.TimeStamper(fmt="iso"),
structlog.processors.JSONRenderer(default_json_serializer),
],
)
)
)
],
)
No response
No response
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too