Repository navigation
feat(server): introduce structured logging (levels, request IDs, JSON) - #273
Conversation
gkhngyk
left a comment
There was a problem hiding this comment.
Thanks @Pallavikumarimdb — really clean Phase 1 (pino + LOG_LEVEL, request-id correlation, redaction, JSON). One blocking issue before merge:
server/src/middleware/request-id.js — wrong logger import path.
import logger from '../../lib/logger.js';The file is at src/middleware/, so ../../lib resolves to server/lib/logger.js (no such dir) — the logger lives at src/lib/logger.js. At startup server.js imports this middleware → ERR_MODULE_NOT_FOUND → the server won't boot. (CI didn't catch it because the server job only runs eslint/prettier/vitest, which don't resolve ESM paths to disk, and there's no startup smoke test.)
Fix is one character — use a single ../ (like middleware/index.js does with ../config/...):
import logger from '../lib/logger.js';Everything else looks good to merge once that's fixed. 🙌
Minor (non-blocking, optional): the redact paths target req.headers.* but the request log currently passes { method, path, origin, ip } rather than the req object, so redaction only kicks in once req itself is logged — fine to leave for a later phase.
@gkhngyk I have made the suggested changes, could you please review again? |
gkhngyk
left a comment
There was a problem hiding this comment.
Import path fixed (../lib/logger.js) — server boots cleanly now. Structured logging Phase 1 looks good: pino, LOG_LEVEL, request-id correlation, redaction, JSON. Thanks @Pallavikumarimdb! 🙌
Summary
Phase 1 of structured logging infrastructure for the server #245.
Changes:
pinoas a dependency for fast, JSON-by-default structured loggingserver/src/lib/logger.js— centralized logger instance with configurableLOG_LEVEL(defaults todebugin development,infoin production) and redaction of sensitive headersserver/src/middleware/request-id.js— attaches a UUID correlation ID to each request (req.id), setsx-request-idresponse header, and provides a per-request child logger (req.log) with the request ID boundserver/src/server.jsto integrate the request ID middleware and replace keyconsole.*calls with structured logger calls at appropriate levels:debuglevel (reduces noise; off by default in production)Env:
LOG_LEVELadded to.env.example(e.g.infoin production,debuglocally)Note: This covers Phase 1 (core infrastructure). Remaining
console.*calls across the codebase will be migrated incrementally in follow-up PRs.Related issue
Type of change
feat— New featurefix— Bug fixchore— Maintenance / dependenciesdocs— Documentation onlyrefactor— Code change that neither fixes a bug nor adds a featuretest— Adding or updating testsChecklist
feature/,fix/,chore/,docs/) — see CONTRIBUTING.mdyarn lintpasses (run fromweb/)yarn typecheckpasses (run fromweb/)yarn format:checkpasses (run fromweb/)