Express Session Logger
express-session-loggerA simple way to add custom context to all logs within your Express session. Attach request IDs, user info, or any contextual metadata to every log line automatically.
Installation
npm install express-session-loggeryarn add express-session-loggerWhy it exists
Debugging production issues in Express APIs is painful when your logs have no correlation between requests. This middleware solves the classic problem of "which log lines belong to this request?". It injects a per-request context (request ID, user ID, session token) into every log call made during that request lifecycle, using Node.js `AsyncLocalStorage` so it propagates through async calls transparently.
Features
Request context flows automatically through all async operations in the request lifecycle using Node.js AsyncLocalStorage — no manual passing required.
Works with any logger. Wraps your existing logger instance and injects context fields into every log call without changing your logging code.
Highlights
- Uses AsyncLocalStorage — no thread-local hacks, works correctly with async/await
- Zero change required to your existing logger calls — wrap once, context propagates automatically
- Configurable context factory: attach whatever fields make sense for your app
- Compatible with Winston, Pino, Bunyan, and console