Skip to content

feat(server): introduce structured logging (levels, request IDs, JSON) #245

Closed

Description

@gkhngyk

Summary

The server has no structured logging. A sweep of server/src finds 166 console.* calls across 22 files, with no logger library (no pino/winston/bunyan), no log levels, no correlation/request IDs, and no JSON output. Everything is a flat string written at a single implicit level.

Why it matters

  • No log levels — verbosity can't be tuned per environment; debug-grade chatter ships to production logs unconditionally, inflating cost and hurting signal-to-noise.
  • No correlation/request ID — the tracking pipeline spans many await steps, but there's no way to tie one request's log lines together. This is the most painful gap when debugging a single failing run in the cloud.
  • No JSON format — log aggregators (Vercel/Datadog/etc.) can't parse or filter flat strings; you can't query by level, requestId, route, or status.
  • Unconditional per-request IP/origin logging — server/src/server.js:40 logs method / path / origin / ip on every request. That's both noise and a mild PII concern; with levels it would belong at debug.

Suggested approach (phased — not one giant PR)

Phase 1 — core (this issue, or its first PR):

  • Add a small server/src/lib/logger.js wrapping a structured logger. pino is the natural fit for ESM Node — fast, JSON by default, levels built in.
  • Add a request-ID middleware that attaches a correlation id (req.id) and exposes a per-request child logger.
  • Convert the per-request access log at server.js:40 to the structured logger and move it to debug level (so it's off by default in production).
  • Pick the level from an env var, e.g. LOG_LEVEL (default info in prod, debug locally), and document it in server/.env.example.

Phase 2 — migration (follow-up PRs):

Scope note

This is a cross-cutting infrastructure change touching ~22 files, so it is not a good-first-issue — Phase 1 is a focused, reviewable PR; Phase 2 should land incrementally rather than as a single 166-call rewrite.

Activity

  1. added
    enhancement
    on Jun 12, 2026
  2. Pallavikumarimdb commented on Jun 15, 2026

    @Pallavikumarimdb
    Contributor

    @gkhngyk Can I work on this issue?

  3. gkhngyk commented on Jun 16, 2026

    @gkhngyk
    ContributorAuthor

    Hi @Pallavikumarimdb, thanks for your interest! I've assigned this issue to you. Feel free to reach out if you have any questions. Happy coding!

  4. gkhngyk commented on Jun 26, 2026

    @gkhngyk
    ContributorAuthor

    Phase 1 is complete — the core structured-logging infrastructure shipped in #273 (thanks @Pallavikumarimdb 🙏):

    • server/src/lib/logger.js — pino with configurable LOG_LEVEL + sensitive-header redaction
    • server/src/middleware/request-id.js — per-request req.id correlation ID + req.log child logger
    • wired into server.js (per-request access log moved to debug, CORS/socket/startup routed through the logger)

    Since this issue's title is "introduce structured logging" and that infrastructure now exists, I'm closing it as completed.

    Phase 2 (migrating the remaining ~123 console.* calls across 23 files to the logger) is tracked in a dedicated, file-by-file issue: #303. @Pallavikumarimdb — you're very welcome to continue there if you'd like to keep going.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions