litestar
litestar copied to clipboard
Better Logging Interface (Also simplified)
@Alc-Alc In my experience, the interface does not seem accessible (read: not easy) compared to other features of litestar. It seems to be a wrapper around https://docs.python.org/3/library/logging.config.html#logging-config-dictschema. While stdlib logging is not the greatest, I would be happy with a higher abstraction that makes this easier to use, even if it means losing out on some fine-grained config (in which case I would be ok to fallback to the current interface)
- https://discord.com/channels/919193495116337154/1182745702942646313/1185461662682206289
[!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.
An item to the wishlist: pass Exception instance to the LogConfig.exception_logging_handler in 3.0. This was https://github.com/litestar-org/litestar/issues/3019 but that was closed and I was suggested to write here.
Use case: Sometimes, you want to customize logging based on exception type (e.g. not log HTTPException, at least 4XX ones, as ERROR with stacktrace but as INFO) . It's possible to disable the default exception logging by setting LogConfig(log_exceptions="never") and then use Litestar(after_exception_handler=...) instead to do custom logging here. However, it's maybe a bit confusing having to do that, because LogConfig(exception_logging_handler=...) is intended for doing the logging.
A workaround exists, you can just call sys.exc_info() to get the exception now, but it would be more obvious if it was just passed in.
Not sure if I really grasp the logging problem at hand: But I was wondering if loguru could be a nice logging solution for litestar. Comes with a lot of great features out of the box and is my go-to logging solution currently.
I propose we remove litestar.logging, and Litestar.logging_config for v3, and instead either emit our log messages via standard library logging, or let a user pass in a logger object that conforms the stdlib logging interface (or perhaps a combination of both).
My main concern is its unnecessary. We don't need a tight coupling to the user's logging configuration to operate the application, and the convenience payoff doesn't return enough to outweigh the complexity this brings to our code base, and to our user's configurations.
Personally, I would be fine with both, loguru or the standard logging library. I don't care what is used under the hood, but I care how easy and fast I can use it with Litestar. As such, I'm more concerned how it is documented. :smiley_cat:
I've opened https://github.com/orgs/litestar-org/discussions/3482#discussioncomment-9376183 because the documentation couldn't answer my questions.
So please, whatever you implement, take into account that this new feature is only done when it's probably documented. :wink:
Many thanks for all your time and dedication! :heart: