feat(middleware): add RequestLogger for structured access logs#167
Open
kellylimmm wants to merge 1 commit into
Open
feat(middleware): add RequestLogger for structured access logs#167kellylimmm wants to merge 1 commit into
middleware): add RequestLogger for structured access logs#167kellylimmm wants to merge 1 commit into
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Links #132
🚀 Summary
Adds a
RequestLoggerHTTP middleware that emits one structured JSON access-log entry per request. This gives the platform visibility into traffic patterns, latency, and server errors without relying on per-handler logging, and ensures every request can be traced end-to-end via the existingrequest_idcorrelation.✏️ Changes
RequestLoggermiddleware (server/internal/middleware/request_logger.go) that logsmethod,path,status, andduration_msper request.responseRecorderto capture the response status code viahttp.ResponseWriterinterception.Errorlevel so monitoring tooling can alert on server errors directly from log levels.RequestLoggerinto the middleware chain inserver/cmd/tw/main.goimmediately afterRequestID, so every access log entry inherits therequest_idfield.WriteHeadercalls, implicit 200 viaWrite, 5xx → ERROR level, and 4xx (non-5xx) → INFO level.🧪 Test Plan
go test ./server/internal/middleware/...— all subtests pass.go build ./...— clean build.go vet ./...— no issues.go run ./server/cmd/twand exercised:GET /→INFOlog line withstatus:200.POST /otp/requestwith invalid body →INFOlog line withstatus:422.X-Request-Idheader on each response matches therequest_idfield in the corresponding log entry.