Skip to content

Replace bare console.* calls with the structured logger #379

@greatest0fallt1me

Description

@greatest0fallt1me

Description

The project provides a structured logger (src/logger.ts) that auto-prepends the request id and redacts sensitive keys (redactLogArguments, SENSITIVE_LOG_KEYS), but several runtime modules still call console.* directly, bypassing redaction and request-id correlation. Direct calls live in src/routes/proxyRoutes.ts:254,258,317,347,358, src/services/revenueSettlementService.ts:123,184,190, src/services/billing.ts:379, src/webhooks/webhook.dispatcher.ts:98,105,110,118, src/routes/usage.ts:125, src/lib/circuitBreaker.ts:137,179, src/app.ts:155,181, plus startup/config paths in src/index.ts:347,376 and src/config/env.ts:143,145. This issue routes runtime logging through the structured logger.

Requirements and context

  • Replace runtime console.error/console.warn/console.log in request- and job-handling code (src/routes/proxyRoutes.ts, src/routes/usage.ts, src/services/revenueSettlementService.ts, src/services/billing.ts, src/webhooks/webhook.dispatcher.ts, src/lib/circuitBreaker.ts, src/app.ts) with the exported logger from src/logger.ts.
  • Preserve the intentional console wrappers inside src/logger.ts itself (info: wrapLog(console.log) etc.) — do not "fix" those.
  • For very early bootstrap/config-failure output (src/config/env.ts:143-145, and the listen/fatal logs in src/index.ts:347,376), either migrate to the logger or document why a raw write is required before the logger is available.
  • Non-functional: keep messages and severities equivalent (a console.error becomes logger.error), and ensure no sensitive values are passed unredacted now that they flow through redactLogArguments.

Acceptance criteria

  • No runtime module under src/ (excluding src/logger.ts and *.test.ts) calls console.* for normal logging.
  • logger.error/logger.warn/logger.info are used with equivalent severity to the calls they replace.
  • Request-scoped logs carry the request id where a request context is available.
  • The intentional wrappers in src/logger.ts are unchanged.
  • Any remaining raw bootstrap writes are explicitly justified in a code comment.
  • A lint rule or test guards against new bare console.* usage in src/ runtime code.

Suggested execution

1. Fork the repo and create a branch

git checkout -b improvement/structured-logging

2. Implement changes — swap calls across the files listed above; optionally add a no-console ESLint override in eslint.config.js scoped to src/ (excluding logger.ts).
3. Write/extend tests — extend src/logger.test.ts; add a guard test asserting no bare console.* in runtime source.
4. Test and commit

npm run lint
npm run typecheck
npm test -- logger --runInBand

Example commit message

refactor(logging): route runtime logs through structured logger

Guidelines

Keep the repo's 90%+ coverage target (README.md). No public API changes, so focus JSDoc on any new logging helper. End state should make the observability story consistent. 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