refactor(backend): replace console logs with Winston logger#309
refactor(backend): replace console logs with Winston logger#309drb101005 wants to merge 2 commits into
Conversation
✅ Deploy Preview for github-spy ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughStructured logging is introduced via a new Winston logger module configured with custom formatting for timestamps and log levels. The logger dependency is added to package.json, and server startup code replaces console.log calls with structured logger calls for MongoDB connection events and error reporting. ChangesStructured Logging Setup
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🎉 Thank you @drb101005 for your contribution. Please make sure your PR follows https://github.com/GitMetricsLab/github_tracker/blob/main/CONTRIBUTING.md#-pull-request-guidelines
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@backend/logger.js`:
- Around line 4-6: The log formatter (logFormat using printf) currently uses
`${stack || message}` which drops the primary message when a stack exists;
change the format to always include the message and append the stack on a new
line when present (e.g., format string that emits message first and
conditionally adds `\n${stack}`), updating the printf callback that references
level, message, timestamp and stack so both message and stack are preserved in
the output.
- Around line 8-14: The logger configuration created by createLogger should
include Winston's errors format so Error objects' stacks are captured
automatically; update the format combine(...) used for logger and for the
transports.Console format to include format.errors({ stack: true }) (i.e., add
errors({ stack: true }) alongside timestamp() and logFormat) so
logger.error(err) and logger.error('msg', err) will include stack traces without
manual deconstruction in server.js; ensure the identifiers createLogger, logger,
logFormat, and transports.Console are updated accordingly.
In `@backend/server.js`:
- Line 40: The log call using logger.error('MongoDB connection error', {
message: err.message, stack: err.stack }) causes the metadata 'message' to
overwrite the main message; change the call in the MongoDB error handler (the
logger.error invocation) to either pass the Error object directly
(logger.error('MongoDB connection error', err)) if you've added Winston's
errors() format, or, if you must keep the current logger config, put the error
under a non-colliding key (e.g., logger.error('MongoDB connection error', {
error: err })) and update the logger format to read error.stack/message.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 473e3985-fef2-4c45-a237-e4cd7c1479cd
📒 Files selected for processing (3)
backend/logger.jsbackend/package.jsonbackend/server.js
Implemented structured logging in the backend by replacing direct console.log usage in server.js with a centralized Winston logger.
This improves log readability and makes it easier to control logging behavior across different environments.
Changes Made
Added a reusable logger.js utility using Winston
Replaced existing console.log and error logs with:
logger.info()
logger.error()
Added configurable log levels using NODE_ENV / LOG_LEVEL
Included timestamps and better error formatting with stack traces
Added winston dependency to package.json
Files Updated
logger.js
server.js
package.json
Closes Feature: Replace console.log Usage in {server.js} with Structured Logging #308
Summary by CodeRabbit