Skip to content

feat: include query parameters in request logs#797

Merged
seapagan merged 3 commits intomainfrom
feature/logging-query-params
Dec 30, 2025
Merged

feat: include query parameters in request logs#797
seapagan merged 3 commits intomainfrom
feature/logging-query-params

Conversation

@seapagan
Copy link
Owner

Summary

  • Enhanced logging middleware to include query parameters in file logs
  • Logs now match uvicorn's console output format with full request paths

Problem

The loguru file logging was only capturing the path (/api/users) without query parameters, unlike uvicorn's console output. This made it difficult to debug issues and detect abuse patterns.

Before:

127.0.0.1 - "GET /api/users" 200 (0.045s)

After:

127.0.0.1 - "GET /api/users?page=2&limit=10" 200 (0.045s)

Changes

Modified LoggingMiddleware in app/middleware/logging_middleware.py to append query string to path when present. Maintains backward compatibility - requests without query params are logged unchanged.

🤖 Generated with Claude Code

Update LoggingMiddleware to log the full request path including query
parameters, matching uvicorn's console output format. This provides
critical information for debugging and detecting abuse patterns.

Example log output:
127.0.0.1 - "GET /api/users?page=2&limit=10" 200 (0.045s)
@codacy-production
Copy link

codacy-production bot commented Dec 30, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
+0.00% (target: -1.00%) 100.00%
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (aa93e38) 1921 1921 100.00%
Head commit (48e7c98) 1924 (+3) 1924 (+3) 100.00% (+0.00%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#797) 3 3 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

@seapagan seapagan self-assigned this Dec 30, 2025
@seapagan seapagan added the enhancement New feature or request label Dec 30, 2025
Add two unit tests to verify query parameters are correctly logged:
- test_middleware_logs_query_parameters: ensures query params are
included
- test_middleware_logs_without_query_parameters: ensures clean output
without trailing ?

Coverage for logging_middleware.py now at 100%.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the logging middleware to include query parameters in request logs, matching uvicorn's console output format. This improvement helps with debugging and detecting abuse patterns by providing complete request information in log files.

Key changes:

  • Modified LoggingMiddleware.dispatch() to append query strings to the path when present
  • Added comprehensive test coverage for both query parameter and non-query parameter scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
app/middleware/logging_middleware.py Enhanced logging to include query parameters in the logged request path, maintaining backward compatibility for requests without query strings
tests/unit/test_logging.py Added two new test cases covering query parameter inclusion and proper handling of requests without query parameters

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Remove unnecessary str() conversion on request.url.path as it already
returns a string type in Starlette.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@seapagan seapagan merged commit 4434265 into main Dec 30, 2025
23 checks passed
@seapagan seapagan deleted the feature/logging-query-params branch December 30, 2025 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants