fix: convert to JSON structured logging using log/slog#102
Conversation
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Coverage Report for CI Build 26001526437Coverage increased (+1.2%) to 40.099%Details
Uncovered Changes
Coverage Regressions5 previously-covered lines in 3 files lost coverage.
Coverage Stats
💛 - Coveralls |
|
@gemini-pr-agent the PR doesnt seem to add a request middleware for GIN, can you add please? |
The requested request middleware has been implemented for the Gin router.
### Summary of Changes
1. **Created **: Added a new Gin middleware called which logs the status, method, path, query, latency, and client IP of every request.
2. **Updated **:
* Imported .
* Registered in the chain of the API server.
The code has been verified and compiles correctly.
|
@gemini-pr-agent is it necessary to have both: middleware.RequestLogger(),
gin.LoggerWithWriter(gin.DefaultWriter, "/healthz", "/metrics"),Also:
|
The `RequestLogger` middleware has been refactored to support variadic exclude paths and now mirrors the implementation pattern from the requested repository. Unit tests have been added to verify that the middleware correctly logs standard requests and skips excluded paths. ### Changes Summary - **Refactored `internal/middleware/request.go`**: Updated `RequestLogger` to accept a logger and variadic `excludedPaths`. It now correctly filters requests based on the provided paths and uses the `slog` logger with consistent formatting. - **Updated `cmd/api_server.go`**: Updated the middleware configuration to pass `slog.Default()` and the excluded paths (`/healthz` and `/metrics`) to `RequestLogger`. - **Added `internal/middleware/request_test.go`**: Created new unit tests to confirm the logging behavior and path exclusion logic, ensuring they function as expected in `gin` environments. Tests have been verified to pass using `go test`.
|
The Changes Summary
Tests have been verified to pass using |
|
@gemini-pr-agent can you explain logger.go please? |
|
The Key Functionality:
This approach ensures consistent, structured logging across the entire API server. |
- Moved `pkg/logger` to `internal/logger.go` to enforce internal usage.
- Standardized application initialization by returning the logger
instance.
- Updated `godx` diagnostics to consume the configured logger.
- Removed redundant Gin logger middleware to streamline output.
```mermaid
graph LR
subgraph Initialization
A[Entry Point] --> B[internal.SetupLogger]
B --> C[godx.Diagnostics]
end
```
This is an automated PR generated by Gemini in response to issue #101.
Summary
The codebase has been refactored to use Go's
log/slogfor structured JSON logging, following the patterns in the provided reference.Key Changes:
pkg/logger/logger.goto initialize the globalsloglogger with aJSONHandler.logpackage withlog/slogacross allcmd/,internal/, andinternal/importer/files.log.Printfwithslog.Info,slog.Error, andslog.Warnusing structured key-value pairs.log.Fatalfwithslog.Errorfollowed byos.Exit(1)to maintain correct exit behavior while allowing for structured logging.sloglogger.All tests passed successfully following the refactor.
Caution
Please review the generated code carefully before merging!
Closes #101