litestar
litestar copied to clipboard
Add logging middleware (411) draft
PR Checklist
- [x] Have you followed the guidelines in
CONTRIBUTING.md
? - [x] Have you got 100% test coverage on new code?
- [x] Have you updated the prose documentation?
- [x] Have you updated the reference documentation?
Hello,
This is a draft PR for #411 because I am unsure of what is required to satisfy the issue. It's actuall my my first PR on public repo and I've got a lot of questions.
- I've chosen to configure logging at startup => is it a good idea ?
- Logging configuration is in starlite.logging not in starlite.config => should we move it ?
- I've chose to put Logging middleware in starlite.middlewares but I could have put it in starlite.logging => what would be the best ?
- My test, although it cover my code at 100% is very small (but the also is the middleware) => do you have any idea of edge case that I should add ?
- I log both incoming and outgoing event. Most web framework log only outgoing. What do you think should be the default ? Should I add specific configuration in LoggingConfig for activate incoming, outgoing, both ?
- I log those informations : '{hostname}:{port} - {method} {path} {scheme}/{http_version} {result}' (outgoing example: testserver:8000 - GET /my/path HTTPS/1.1 200), do you want more or less informations ?
- I've got the port from request.base_url.port, is it the good one (there also are ports in scope with server and client) ?
I need help on one failing test: test_request_body_logging_middleware in tests/middleware/test_middleware_handling.py. Initialize logging breaks capslog fixture. Anyone encouter this situation and knows how to make capslog working ?
Improvements:
- In order to ease making custom LoggingMiddleware, I am thinking adding a get_logging_middleware() to LoggingConfig. Is it a good idea ? Should I do that in that PR or make another one ?
Thank you all for your help and recommandations.
Swann
I'll try to take a look at this tonight if this is still an issue.
We probably also need to add tests using the picologging
logger as well.
@Swannbm please convert this PR to a draft (it should be on the right side pane)l.
Converted this PR to a draft
Here the minutes of my (quick) discussion with Goldziher:
- Copy SessionMiddleware to fetch the middleware from Config instance
- Do not init logging up front, let the user do the job
- Extend LoggingConfig with properties only for the middleware
- keep current file organization to avoid breaking change (LoggingConfig will stay in logging.init.py)
All this points are opened to discussion.
Here the minutes of my (quick) discussion with Goldziher:
- Copy SessionMiddleware to fetch the middleware from Config instance
- Do not init logging up front, let the user do the job
- Extend LoggingConfig with properties only for the middleware
- keep current file organization to avoid breaking change (LoggingConfig will stay in logging.init.py)
All this points are opened to discussion.
Rebase on development 😉, the LoggingConfig
was moved.
I have made the change (and necessary revert). I havn't check test coverage yet, I will do it later, my free time is comming to an end for today. @Goldziher and @cofin (even @john-ingles ) could you have a code review please ?
any updates?