Open Source Packages

Express Session Logger

express-session-logger
npmDeveloper Toolsv0.0.5MIT

A 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.

Published Jan 2022
Updated Jun 2023

Installation

$npm install express-session-logger
$yarn add express-session-logger

Why 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

🔄Automatic Context Propagation

Request context flows automatically through all async operations in the request lifecycle using Node.js AsyncLocalStorage — no manual passing required.

📝Logger Agnostic

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
expressloggingmiddlewarenodejssession

References & Links