Description
The repo ships a Pino logger at src/utils/logger.ts and uses it for per-request logs in src/middleware/requestLogger.ts, but the rest of the backend logs through raw console.* — over 120 calls across services including src/services/reconciliationService.ts, src/services/drawWebhookService.ts, src/services/jobQueue.ts, src/services/reconciliationWorker.ts, and src/services/sorobanRpcClient.ts. This produces unstructured stdout that defeats the JSON-log story in docs/OBSERVABILITY.md. This issue migrates service-layer logging to Pino while preserving the existing Stellar-address redaction.
Requirements and context
- Replace
console.log/warn/error in the service layer with the Pino logger from src/utils/logger.ts, keeping log levels meaningful (info/warn/error).
- Preserve redaction:
src/services/horizonListener.ts already routes through redactLogArgs from src/utils/logRedact.ts; ensure migrated call sites apply the same masking so no raw Stellar address leaks.
- Prefer structured fields (e.g.
logger.info({ drawId, attempt }, 'msg')) over interpolated strings so logs are queryable.
- Keep CLI entrypoints (
src/db/migrate-cli.ts, src/db/validate-cli.ts) human-readable, but route their diagnostics through the logger as well unless a plain console line is justified in a comment.
- Non-functional: no behavioral change to control flow; tests that spy on
console must be updated to spy on the logger.
Acceptance criteria
Suggested execution
1. Fork the repo and create a branch — git checkout -b improvement/pino-service-logging.
2. Implement changes — edit the service files under src/services/ and the src/db/*-cli.ts entrypoints to use src/utils/logger.ts.
3. Write/extend tests — Vitest + Supertest; update spies in src/services/__tests__/drawWebhookService.test.ts and src/__tests__/reconciliation.integration.test.ts to assert on the logger.
4. Test and commit —
npm run lint
npm run typecheck
npm test
npm run test:coverage
npm run build
Example commit message
refactor(logging): route service-layer logs through Pino with redaction
Guidelines
CI enforces a 95% coverage threshold (vitest.config.ts, via npm run test:coverage) — keep coverage at or above it after updating spies. Update docs/OBSERVABILITY.md. Timeframe: 96 hours.
Description
The repo ships a Pino logger at
src/utils/logger.tsand uses it for per-request logs insrc/middleware/requestLogger.ts, but the rest of the backend logs through rawconsole.*— over 120 calls across services includingsrc/services/reconciliationService.ts,src/services/drawWebhookService.ts,src/services/jobQueue.ts,src/services/reconciliationWorker.ts, andsrc/services/sorobanRpcClient.ts. This produces unstructured stdout that defeats the JSON-log story indocs/OBSERVABILITY.md. This issue migrates service-layer logging to Pino while preserving the existing Stellar-address redaction.Requirements and context
console.log/warn/errorin the service layer with the Pino logger fromsrc/utils/logger.ts, keeping log levels meaningful (info/warn/error).src/services/horizonListener.tsalready routes throughredactLogArgsfromsrc/utils/logRedact.ts; ensure migrated call sites apply the same masking so no raw Stellar address leaks.logger.info({ drawId, attempt }, 'msg')) over interpolated strings so logs are queryable.src/db/migrate-cli.ts,src/db/validate-cli.ts) human-readable, but route their diagnostics through the logger as well unless a plain console line is justified in a comment.consolemust be updated to spy on the logger.Acceptance criteria
console.*remains insrc/services/**(verifiable via grep), routed through Pino instead.error, retries atwarn, lifecycle atinfo).consolespies are updated and pass.docs/OBSERVABILITY.mdreflects that the service layer emits structured Pino logs.Suggested execution
1. Fork the repo and create a branch —
git checkout -b improvement/pino-service-logging.2. Implement changes — edit the service files under
src/services/and thesrc/db/*-cli.tsentrypoints to usesrc/utils/logger.ts.3. Write/extend tests — Vitest + Supertest; update spies in
src/services/__tests__/drawWebhookService.test.tsandsrc/__tests__/reconciliation.integration.test.tsto assert on the logger.4. Test and commit —
npm run lint npm run typecheck npm test npm run test:coverage npm run buildExample commit message
Guidelines
CI enforces a 95% coverage threshold (
vitest.config.ts, vianpm run test:coverage) — keep coverage at or above it after updating spies. Updatedocs/OBSERVABILITY.md. Timeframe: 96 hours.