fix: replace console.log with structured JSON logger in backend/server.js#312
fix: replace console.log with structured JSON logger in backend/server.js#312Goutam-2702 wants to merge 2 commits into
Conversation
…tMetricsLab#308) Replaces all three console.log calls with a zero-dependency structured logger that emits JSON log lines. Logs are suppressed in test/production environments via NODE_ENV check. Closes GitMetricsLab#308
✅ Deploy Preview for github-spy ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe backend server replaces ad-hoc console.log calls with an in-file structured JSON logger that suppresses output in tests, routes error-level logs to stderr and others to stdout, and logs MongoDB connection events and server startup (with port metadata). ChangesStructured Logging Implementation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ 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 @Goutam-2702 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: 1
🤖 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/server.js`:
- Around line 32-34: The comment for the "Structured logger" is incorrect: it
claims verbose logs are suppressed in production and tests, but the
implementation only gates suppression on NODE_ENV === 'test'; update the comment
near the structured logger to accurately state that verbose logs are suppressed
in tests (NODE_ENV === 'test') while remaining available in production and
development, referencing the existing NODE_ENV check so readers can find the
behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Summary
Closes #308
Replaces all three bare
console.log/console.errorcalls inbackend/server.jswith a lightweight structured logger that emits JSON log lines tostdout/stderr.Why no new dependency?
Adding
winstonorpinowould require updatingpackage.json,package-lock.json, and potentially CI caching -- increasing review surface. The inline logger achieves the same structured-output goal with zero overhead and is trivially replaceable with a full logging library later.Changes
console.log('Connected to MongoDB')logger.info('Connected to MongoDB')console.log('Server running on port ...')logger.info('Server started', { port })console.log('MongoDB connection error:', err)logger.error('MongoDB connection error', { error, stack })Logger behaviour
NODE_ENV=test-> all output suppressed (safe for unit tests)NODE_ENV=production-> JSON lines emitted;errorlevel goes tostderrNODE_ENV=development-> same JSON lines, easy to pipe tojqSample output
{"timestamp":"2025-05-18T04:00:00.000Z","level":"info","message":"Connected to MongoDB"} {"timestamp":"2025-05-18T04:00:00.001Z","level":"info","message":"Server started","port":"5000"}GSSoC '26 Participant: GOUTAM KUMAR GHOSAL
Summary by CodeRabbit