Skip to content

Replace bare console.* calls in the service layer with the Pino structured logger #232

Description

@greatest0fallt1me

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

  • No bare console.* remains in src/services/** (verifiable via grep), routed through Pino instead.
  • All migrated log sites preserve Stellar-address/secret redaction.
  • Log levels are appropriate (errors at error, retries at warn, lifecycle at info).
  • Existing tests that asserted on console spies are updated and pass.
  • docs/OBSERVABILITY.md reflects that the service layer emits structured Pino logs.

Suggested execution

1. Fork the repo and create a branchgit 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions