Skip to content

Conversation

@Naganathan05
Copy link

@Naganathan05 Naganathan05 commented Jul 2, 2025

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:

  • Added a new logger service which uses zerolog
  • Used Error logging level incase of logging the failure that has been from server side (eg: Failure of insertion of record to DB).
  • Used Warn logging level incase of logging the failure due to client side (eg: Invalid projectId in the request).
  • Used Info logging level incase of generic logging for debugging (eg: User preference updated successfully)
  • Used Fatal logging level incase of logging the failures in the service that would cause the service to terminate (eg: Database connection failure).
  • Suppressed logs from GIN-debug, GIN and GORM.

Sample Logs Screenshot:

Screenshot 2025-07-02 215607


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.

  • Refactors
    • Replaced all direct log and print statements with the new logger.
    • Added context-aware log messages across handlers, middleware, and database code.
    • Suppressed noisy logs from Gin and GORM for cleaner output.

Copilot AI review requested due to automatic review settings July 2, 2025 17:35
@kusari-inspector
Copy link

kusari-inspector bot commented Jul 2, 2025

Kusari Analysis Results

Analysis for commit: c154987, performed at: 2025-07-08T18:01:37Z

@kusari-inspector rerun - Trigger a re-analysis of this PR

@kusari-inspector feedback [your message] - Send feedback to our AI and team


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 issues

Dependency Changes

Status Package Change Version Latest Version Advisories License
⚠️ Flagged github.com/mattn/go-colorable added 0.1.14 v0.1.14 None MIT (permissive)
⚠️ Flagged github.com/rs/zerolog added 1.34.0 v1.34.0 None MIT (permissive)

Risk Details

github.com/mattn/go-colorable:
Scorecard Checks for pkg:golang/github.com%2Fmattn%[email protected]:

  • maintained: 0/10
    ⚠️ Repo is not maintained actively in the last 90 days.
  • code-review: 7/10

github.com/rs/zerolog:
Scorecard Checks for pkg:golang/github.com%2Frs%[email protected]:

  • maintained: 0/10
    ⚠️ Repo is not maintained actively in the last 90 days.
  • code-review: 7/10

Copy link

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

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.go with LoggerService and global Log
  • Replaces log, fmt, and log.Printf in various packages with utils.Log.{Info,Warn,Error,Fatal}
  • Initializes logger in main.go and 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")
Copy link

Copilot AI Jul 2, 2025

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")).

Suggested change
fmt.Println("[LOG]: Configuration loaded successfully")
utils.Log.Info("[LOG]: Configuration loaded successfully")

Copilot uses AI. Check for mistakes.
Copy link
Author

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

Copy link

@cubic-dev-ai cubic-dev-ai bot left a 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")
Copy link

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.

Copy link
Author

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))
Copy link

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-inspector
Copy link

Kusari PR Analysis rerun based on - d81baee performed at: 2025-07-02T17:50:12Z - link to updated analysis

@kusari-inspector
Copy link

Kusari PR Analysis rerun based on - c154987 performed at: 2025-07-08T18:01:37Z - link to updated analysis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant