Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: add default_json_serializer to __all__ in litestar.logging.config #3489

Open
keongalvin opened this issue May 11, 2024 · 0 comments
Labels
Enhancement This is a new feature or request

Comments

@keongalvin
Copy link

keongalvin commented May 11, 2024

Summary

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?

Basic Example

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),
                    ],
                )
            )
        )
    ],
)

Drawbacks and Impact

No response

Unresolved questions

No response


Note

While we are open for sponsoring on GitHub Sponsors and
OpenCollective, we also utilize Polar.sh to engage in pledge-based sponsorship.

Check out all issues funded or available for funding on our Polar.sh dashboard

  • If you would like to see an issue prioritized, make a pledge towards it!
  • We receive the pledge once the issue is completed & verified
  • This, along with engagement in the community, helps us know which features are a priority to our users.
Fund with Polar
@keongalvin keongalvin added the Enhancement This is a new feature or request label May 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement This is a new feature or request
Projects
None yet
Development

No branches or pull requests

1 participant