Problem
Observability is fragmented and inconsistent across the backend:
- The custom
Logger utility in src/utils/logger.ts only wraps console.log/error/warn, providing no log levels, structured fields, or transports.
- 20+ raw
console.* statements remain across src/ (middleware, controllers, services).
- There is no request/response logging middleware, making it hard to debug API issues in production.
- The health-check endpoint in
src/index.ts:53-105 mixes Date.now() timing with console.error, producing unstructured output.
- The rate-limit middleware logs via
console.log(allowed, remaining) at rateLimitMiddleware.ts:18.
winston is in package.json but unused.
- No correlation IDs, no consistent error context (user ID, route, stack), no JSON output suitable for production log aggregators.
Proposed Solution
- Create
src/middleware/requestLoggingMiddleware.ts that logs every incoming request (method, path, query, authenticated user ID when available) and the outgoing response (status, duration in ms, response size).
- Refactor
src/utils/logger.ts to delegate to Winston with JSON formatter and configurable transports (console + file).
- Wire the logging middleware into the Express app in
src/index.ts.
- Replace
console.* calls in middleware, auth, services, and controllers with logger.info/warn/error calls (priority: middleware and auth paths).
- Update the health-check endpoint to emit structured logs via the logger instead of raw
console.
- Add
tests/logging.test.ts that verifies a request/response cycle emits a log line with the expected fields.
Acceptance Criteria
Out of Scope
- Adding APM/distributed tracing (OpenTelemetry) — separate effort.
- Shipping logs to an external aggregator (Datadog, Loki, etc.).
Suggested Labels
enhancement, observability, developer-experience
Problem
Observability is fragmented and inconsistent across the backend:
Loggerutility insrc/utils/logger.tsonly wrapsconsole.log/error/warn, providing no log levels, structured fields, or transports.console.*statements remain acrosssrc/(middleware, controllers, services).src/index.ts:53-105mixesDate.now()timing withconsole.error, producing unstructured output.console.log(allowed, remaining)atrateLimitMiddleware.ts:18.winstonis inpackage.jsonbut unused.Proposed Solution
src/middleware/requestLoggingMiddleware.tsthat logs every incoming request (method, path, query, authenticated user ID when available) and the outgoing response (status, duration in ms, response size).src/utils/logger.tsto delegate to Winston with JSON formatter and configurable transports (console + file).src/index.ts.console.*calls in middleware, auth, services, and controllers withlogger.info/warn/errorcalls (priority: middleware and auth paths).console.tests/logging.test.tsthat verifies a request/response cycle emits a log line with the expected fields.Acceptance Criteria
console.*statements in middleware and auth paths are replaced with logger calls.console.erroror ad-hocDate.now()prints).console.logleft in the hot path.timestamp,level,message, and request context fields.Out of Scope
Suggested Labels
enhancement,observability,developer-experience