Skip to content
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

feat(BUX-605): gin logs & debugPrint handled by zerolog #207

Merged
merged 4 commits into from
Feb 20, 2024

Conversation

chris-4chain
Copy link
Contributor

@chris-4chain chris-4chain commented Feb 19, 2024

Pull Request Checklist

  • πŸ“– I created my PR using provided : CODE_STANDARDS
  • πŸ“– I have read the short Code of Conduct: CODE_OF_CONDUCT
  • 🏠 I tested my changes locally.
  • βœ… I have provided tests for my changes.
  • πŸ“ I have used conventional commits.
  • πŸ“— I have updated any related documentation.
  • πŸ’Ύ PR was issued based on the Github or Jira issue.

This PR addresses several aspects of logging within a Gin application:

  • Internal debugPrint function: Gin's internal debugPrint function implemented in gin as: (fmt.Fprintf(DefaultWriter, "[GIN-debug] " + format, values...)) has been configured to use our zerolog logger by setting the DefaultWriter early in the initialization process.
  • Error Logging: The DefaultErrorWriter has also been set to use our zerolog logger. This ensures that errors, such as those caught by gin.Recovery(), are logged consistently.
  • Request Logging Middleware: I've created custom Gin middleware to log incoming requests in a structured format using zerolog. This ensures that request data (path, status code, etc.) is captured in well-defined fields for easier analysis.

How it works:

  1. When debug mode is enabled, Gin's startup messages are logged through our zerolog setup (customized DefaultWriter).
  2. Our custom middleware intercepts each request and generates a structured zerolog record.
  3. Gin's standard Recovery middleware now logs errors and panics to zerolog (customized DefaultErrorWriter).

Release Mode:

I've added a new configuration option release_mode (true/false) to control Gin's debug mode. Setting this to true is essential for production environments.

Example log record:
image

Info about DefaultWriter:
gin-gonic/gin#1877 (comment)

Copy link
Contributor

github-actions bot commented Feb 19, 2024

Manual Tests

πŸ’š Manual testing by @pawellewandowski98 resulted in success.

@pawellewandowski98 pawellewandowski98 added the tested PR was tested by a team member label Feb 19, 2024
transports/http/server/gin_loggers.go Outdated Show resolved Hide resolved
config.example.yaml Outdated Show resolved Hide resolved
@chris-4chain chris-4chain removed the tested PR was tested by a team member label Feb 20, 2024
@pawellewandowski98 pawellewandowski98 added the tested PR was tested by a team member label Feb 20, 2024
@chris-4chain chris-4chain merged commit fb91b8c into master Feb 20, 2024
9 of 10 checks passed
@chris-4chain chris-4chain deleted the feat-605-gin-logger branch February 20, 2024 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tested PR was tested by a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants