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 (or nest-winston) and configure as the NestJS logger
- Replace all
console.log/console.error calls 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_LEVEL env 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
Technical Context
- Main bootstrap:
backend/src/main.ts — replace Logger usage
nestjs-pino is the most popular NestJS logging integration: https://github.com/iamolegga/nestjs-pino
- Request context: use
pino-http middleware for automatic request logging
- Correlation IDs: use
nestjs-pino's req.id or X-Request-Id header
- Redaction: use
pino's redact option for sensitive fields
What
Replace all
console.logandconsole.errorcalls 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.logfor logging (visible inmain.tsand likely scattered across services). For a health credential platform in production, this is insufficient:SECURITY.md mentions Sentry and Datadog integration — structured logging is the prerequisite for both.
Scope
In scope:
nestjs-pino(ornest-winston) and configure as the NestJS loggerconsole.log/console.errorcalls with proper logger methodsLOG_LEVELenv var to.env.exampleOut of scope:
backend/src/audit/)Acceptance Criteria
nestjs-pino(ornest-winston) is installed and configuredconsole.logandconsole.errorcalls inbackend/src/are replacedLOG_LEVELenv var controls minimum log levelnpm run start:devshows colored, readable logsnpm run start:prodoutputs JSON logsTechnical Context
backend/src/main.ts— replaceLoggerusagenestjs-pinois the most popular NestJS logging integration: https://github.com/iamolegga/nestjs-pinopino-httpmiddleware for automatic request loggingnestjs-pino'sreq.idorX-Request-Idheaderpino'sredactoption for sensitive fields