Repository navigation
Replace console.log with structured logging using Winston or Pino #161
Copy link
Copy link
Closed
Labels
GrantFox OSSIssue tracked in GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignCampaign: Third CampaignbackendBackend related issuesBackend related issuesdifficulty:hardHard difficulty issuesHard difficulty issuesobservabilityLogging, monitoring, tracingLogging, monitoring, tracingpriority:highHigh priority issuesHigh priority issues
Description
What
Replace all console.log and console.error calls in the backend with structured logging using Pino (or Winston). Add log levels, JSON output format, request context (request ID, user ID), and correlation IDs for tracing requests across services.
Why
The backend currently uses console.log for logging (visible in main.ts and likely scattered across services). For a health credential platform in production, this is insufficient:
- No log levels (can't filter noise from critical errors)
- No structured format (can't query logs in CloudWatch/Datadog)
- No request correlation (can't trace a single request through multiple services)
- No sensitive data filtering (health data could leak into logs)
SECURITY.md mentions Sentry and Datadog integration — structured logging is the prerequisite for both.
Scope
In scope:
- Install
nestjs-pino(ornest-winston) and configure as the NestJS logger - Replace all
console.log/console.errorcalls with proper logger methods - Add request logging middleware (method, path, status, duration, request ID)
- Add log levels: debug, info, warn, error
- JSON format in production, pretty-print in development
- Add
LOG_LEVELenv var to.env.example
Out of scope:
- Shipping logs to external services (Datadog, CloudWatch)
- Log rotation configuration
- Audit logging (already exists in
backend/src/audit/) - Frontend logging
Acceptance Criteria
-
nestjs-pino(ornest-winston) is installed and configured - All
console.logandconsole.errorcalls inbackend/src/are replaced - HTTP requests are logged with: method, path, status code, duration, request ID
- Log output is JSON in production, pretty-printed in development
-
LOG_LEVELenv var controls minimum log level - Sensitive fields (passwords, tokens, health data) are redacted from logs
-
npm run start:devshows colored, readable logs -
npm run start:prodoutputs JSON logs
Technical Context
- Main bootstrap:
backend/src/main.ts— replaceLoggerusage nestjs-pinois the most popular NestJS logging integration: https://github.com/iamolegga/nestjs-pino- Request context: use
pino-httpmiddleware for automatic request logging - Correlation IDs: use
nestjs-pino'sreq.idorX-Request-Idheader - Redaction: use
pino'sredactoption for sensitive fields
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
GrantFox OSSIssue tracked in GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignCampaign: Third CampaignbackendBackend related issuesBackend related issuesdifficulty:hardHard difficulty issuesHard difficulty issuesobservabilityLogging, monitoring, tracingLogging, monitoring, tracingpriority:highHigh priority issuesHigh priority issues
Activity
Wilfred007 commentedon Aug 23, 2026
Hi! I’d like to work on this structured logging improvement. I can migrate the backend from console.log/console.error to a production-ready Pino-based logging system while keeping observability and security in focus.
My approach would include:
Configuring nestjs-pino as the NestJS logger with debug, info, warn, and error levels.
Replacing scattered console calls with structured logger methods.
Adding request IDs and correlation IDs, including request method, path, status, and duration.
Including relevant user/request context while filtering sensitive health or credential data.
Using JSON logs in production and readable pretty-printing in development.
Adding LOG_LEVEL to .env.example.
Testing logging behavior, request context, error handling, and sensitive-data redaction.
I’ll keep the implementation aligned with the existing Sentry/Datadog setup so the resulting logs are easy to search, correlate, and monitor in production.
grantfox-oss commentedon Aug 23, 2026
🦊 GrantFox — @Wilfred007 has been assigned to this issue as part of the Third Campaign campaign!
Next steps:
Closes #161)Good luck! Track your progress on GrantFox.
meshackyaro commentedon Aug 23, 2026
Hi, I'd like to work on this issue. I'd ensure to implement structured logging across the NestJS backend.
Approach & Technical Implementation
nestjs-pinoIntegration: Installnestjs-pinoandpino-httpalong withpino-prettyfor development.pinooffers superior performance compared to Winston, featuring low overhead and native JSON output.LoggerModuleinAppModuleand passapp.useLogger(app.get(Logger))insidebackend/src/main.tsto fully replace NestJS's default internal logger.pino-httpmiddleware to automatically capturemethod,url,statusCode,responseTime, and HTTP headers for incoming requests.X-Request-IDorX-Correlation-IDheaders to bind to the logger context. Fall back tocrypto.randomUUID()when headers are absent, ensuring every request has a stable tracking ID.req.user?.id) dynamically into the request logger context inside the NestJS middleware/interceptor layer.pino-prettywhenNODE_ENV=development(npm run start:dev) for colored, human-readable console output. Switch directly to single-line JSON logs in production (npm run start:prod).LOG_LEVELfrom environment variables (e.g.,debug,info,warn,error) defaulting toinfo.redactconfig to prevent leaking sensitive fields. Mask authorization tokens, passwords, and sensitive health records:Execution Plan
nestjs-pino,pino-http, andpino-prettytopackage.json. DefineLOG_LEVELin.env.exampleand wireLoggerModuleintobackend/src/main.tsandapp.module.ts.console.log,console.error,console.warn, and standardLoggerinstances acrossbackend/src/with the injectedPinoLogger/ Nest JSLoggerabstraction.npm run start:devstreams formatted color logs andnpm run start:prodemits valid, queryable single-line JSON objects.Ready to take this on as soon as assigned!
grantfox-oss commentedon Aug 24, 2026
🎉 This issue has been marked as completed on GrantFox as part of the Third Campaign campaign!
@Wilfred007's PR #174 was approved and merged by @Josie123-Dev.
🏆 @Wilfred007: You earned 40 FoxPoints for this contribution! Your current tier: Builder (1,068 total points). Track your full progress on GrantFox.
👏 Great work, @Wilfred007! Keep contributing to GuardZero144.