-
Notifications
You must be signed in to change notification settings - Fork 19
Chore: Add logger and enhance logging #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Chore: Add logger and enhance logging #301
Conversation
Kusari Analysis ResultsAnalysis for commit: c154987, performed at: 2025-07-08T18:01:37Z • • Recommendation✅ PROCEED with this Pull Request Summary✅ No Flagged Issues Detected All values appear to be within acceptable risk parameters. The PR adds two new Go dependencies (zerolog and go-colorable) that are flagged as risky only due to lack of recent maintenance activity (not actively maintained in the last 90 days). However, both packages are at their latest versions, have acceptable code review practices (7/10), use permissive MIT licenses, and have no known vulnerabilities or advisories. The security code analysis found zero issues across all categories. While the maintenance concern is worth noting, these are stable, widely-used logging utilities that don't present significant security risks. Found this helpful? Give it a 👍 or 👎 reaction! Click to expand for details and specific link to issuesDependency Changes
Risk Detailsgithub.com/mattn/go-colorable:
github.com/rs/zerolog:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds a centralized logger service using zerolog and replaces ad-hoc log/fmt calls with leveled logging across DB initialization, HTTP middleware, handlers, tests, main application, and gRPC servers.
- Introduces
pkg/utils/logger.gowithLoggerServiceand globalLog - Replaces
log,fmt, andlog.Printfin various packages withutils.Log.{Info,Warn,Error,Fatal} - Initializes logger in
main.goand suppresses verbose GIN/GORM debug output
Reviewed Changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/utils/logger.go | New LoggerService wrapper around zerolog |
| pkg/db/db.go | Swapped log.* for utils.Log.*, silent GORM logs |
| pkg/auth/middleware.go | Replaced log.Printf with utils.Log levels |
| pkg/api/routers/routers_test.go | Added error logging via utils.Log in tests |
| pkg/api/handlers/user/user_preference.go | Enhanced request logging and error levels in handlers |
| pkg/api/handlers/user/user_preference_test.go | Updated test prints to utils.Log error logs |
| pkg/api/handlers/project/project.go | Switched project handler logs to utils.Log |
| pkg/api/handlers/project/project_test.go | Updated test prints to utils.Log error logs |
| pkg/api/handlers/handlers.go | Swapped prints and fmt for leveled utils.Log |
| pkg/api/handlers/handlers_test.go | Replaced fmt.Println/fmt.Printf with utils.Log |
| pkg/api/handlers/handler_utils_test.go | Added utils.Log in utility tests |
| main.go | Calls initLogger(), replaces fmt.Println with utils.Log |
| grpcstart/grpcstart.go | Switched shutdown print to utils.Log.Info |
| grpcstart/grpc_server.go | Replaced log/fmt in gRPC implementation |
| go.mod | Added zerolog and colorable dependencies |
| if _, err := config.LoadConfig(); err != nil { | ||
| log.Fatalf("error: %v", err) | ||
| } | ||
| fmt.Println("[LOG]: Configuration loaded successfully") |
Copilot
AI
Jul 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the centralized logger instead of fmt.Println to ensure consistent formatting and output destination (e.g., utils.Log.Info("Configuration loaded successfully")).
| fmt.Println("[LOG]: Configuration loaded successfully") | |
| utils.Log.Info("[LOG]: Configuration loaded successfully") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger service wont be initialized at this stage, using it here would cause an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cubic found 8 issues across 15 files. Review them in cubic.dev
React with 👍 or 👎 to teach cubic. Tag @cubic-dev-ai to give specific feedback.
| if _, err := config.LoadConfig(); err != nil { | ||
| log.Fatalf("error: %v", err) | ||
| } | ||
| fmt.Println("[LOG]: Configuration loaded successfully") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rule violated: Require Proper Logging
Direct use of fmt.Println bypasses the centralized utils.Log logging utility, violating the "Require Proper Logging" rule that mandates using the application logger for all production logs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Logger service wont be initialized at this stage, using it here would cause an error
| // check if favourite entry exists for the user | ||
| var count int64 = 1 | ||
| if err := h.db.Table("preferred_projects").Where("user_id = ? and project_id = ?", user.ID, project.ID).Count(&count).Error; err != nil { | ||
| utils.Log.Warn(fmt.Sprintf("[REQUEST-ERROR]: Favourite project %s already configured for the user for %s at %s", favouriteRequest.Favourite, method, path)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The duplicate-project logic is wrong: this branch executes only when the COUNT query returns an error, not when a duplicate exists, so real duplicates are missed and DB errors are misreported.
|
Kusari PR Analysis rerun based on - d81baee performed at: 2025-07-02T17:50:12Z - link to updated analysis |
|
Kusari PR Analysis rerun based on - c154987 performed at: 2025-07-08T18:01:37Z - link to updated analysis |
Issue #276
Overview:
This PR is for adding a logger service and utilizing it to enhance logging by using various levels of logging that are available.
Key Changes:
zerologErrorlogging level incase of logging the failure that has been from server side (eg: Failure of insertion of record to DB).Warnlogging level incase of logging the failure due to client side (eg: Invalid projectId in the request).Infologging level incase of generic logging for debugging (eg: User preference updated successfully)Fatallogging level incase of logging the failures in the service that would cause the service to terminate (eg: Database connection failure).GIN-debug,GINandGORM.Sample Logs Screenshot:
Summary by cubic
Added a new logger service using zerolog and updated the codebase to use structured logging with different log levels for errors, warnings, info, and fatal events.