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
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.
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 callconsole.*directly, bypassing redaction and request-id correlation. Direct calls live insrc/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 insrc/index.ts:347,376andsrc/config/env.ts:143,145. This issue routes runtime logging through the structured logger.Requirements and context
console.error/console.warn/console.login 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 exportedloggerfromsrc/logger.ts.consolewrappers insidesrc/logger.tsitself (info: wrapLog(console.log)etc.) — do not "fix" those.src/config/env.ts:143-145, and the listen/fatal logs insrc/index.ts:347,376), either migrate to the logger or document why a raw write is required before the logger is available.console.errorbecomeslogger.error), and ensure no sensitive values are passed unredacted now that they flow throughredactLogArguments.Acceptance criteria
src/(excludingsrc/logger.tsand*.test.ts) callsconsole.*for normal logging.logger.error/logger.warn/logger.infoare used with equivalent severity to the calls they replace.src/logger.tsare unchanged.console.*usage insrc/runtime code.Suggested execution
1. Fork the repo and create a branch
2. Implement changes — swap calls across the files listed above; optionally add a
no-consoleESLint override ineslint.config.jsscoped tosrc/(excludinglogger.ts).3. Write/extend tests — extend
src/logger.test.ts; add a guard test asserting no bareconsole.*in runtime source.4. Test and commit
npm run lint npm run typecheck npm test -- logger --runInBandExample commit message
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.