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

docs: Added information about the JSON-like logging format for the standard library #3990

Closed
wants to merge 5 commits into from

Conversation

RenameMe1
Copy link
Contributor

@RenameMe1 RenameMe1 commented Feb 10, 2025

Description

  • I added json format string example in Using Python standard library section
  • I added information about format string style for LogginConfig

Closes

#3827

@RenameMe1 RenameMe1 requested review from a team as code owners February 10, 2025 17:48
@github-actions github-actions bot added area/docs This PR involves changes to the documentation size: small pr/external Triage Required 🏥 This requires triage labels Feb 10, 2025
@RenameMe1 RenameMe1 changed the title Added information about the JSON-like logging format for the standard library draft: Added information about the JSON-like logging format for the standard library Feb 10, 2025
@RenameMe1 RenameMe1 marked this pull request as draft February 10, 2025 17:54
@RenameMe1 RenameMe1 changed the title draft: Added information about the JSON-like logging format for the standard library docs: Added information about the JSON-like logging format for the standard library Feb 10, 2025
Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3990

@RenameMe1 RenameMe1 marked this pull request as ready for review February 10, 2025 18:22
@RenameMe1
Copy link
Contributor Author

A friendly ping @provinzkraut. Could you help me get a review for this PR?

@provinzkraut
Copy link
Member

Not sure if this belongs in the Litestar logging tutorial, as it strictly deals with stdlib logging configuration. Maybe it would be better to link to the stdlib logging docs?

@RenameMe1
Copy link
Contributor Author

Not sure if this belongs in the Litestar logging tutorial, as it strictly deals with stdlib logging configuration. Maybe it would be better to link to the stdlib logging docs?

There are no such examples in the stdlib logging documentation. They are also not listed in the stdlib cookbook.

Maybe I can create a for litestar.logging.config.py the 'JsonFormat` class that will return a string in json format? Usage example:

from litestar import Litestar, Request, get
from litestar.logging import LoggingConfig, JsonFormat


@get("/")
def my_router_handler(request: Request) -> None:
    request.logger.info("inside a request")
    return None


logging_config = LoggingConfig(
    root={"level": "INFO", "handlers": ["queue_listener"]},
    formatters={
        "standard": {"format": JsonFormat(["%(asctime)s", "%(name)s", "%(levelname)s", "%(message)s"])} # {'asctime': '%(asctime)s', 'name': ' %(name)s', 'levelname': ' %(levelname)s', 'message': ' %(message)s'}
    },
    log_exceptions="always",
)

app = Litestar(route_handlers=[my_router_handler], logging_config=logging_config)

I think this is a useful feature.

@provinzkraut
Copy link
Member

There are no such examples in the stdlib logging documentation. They are also not listed in the stdlib cookbook.

Sounds to me like you should make a PR to the stdlib docs then :)
If this is a generally good thing to know, and not specific to Litestar, others might benefit from it as well!

@RenameMe1 RenameMe1 closed this Feb 26, 2025
@RenameMe1
Copy link
Contributor Author

Thanks for feedback. It's was very usefull

@RenameMe1 RenameMe1 deleted the Json-Logging-Example branch February 26, 2025 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs This PR involves changes to the documentation pr/external size: small Triage Required 🏥 This requires triage type/docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants