UNPKG

@treasurenet/logging-middleware

Version:

A lightweight Express.js middleware for structured logging, request ID tracing, and response logging with log4js.

15 lines (12 loc) 343 B
const { AsyncLocalStorage } = require('async_hooks'); const storage = new AsyncLocalStorage(); const context = { run: (reqId, callback) => { storage.run(new Map([['reqId', reqId]]), callback); }, get: (key) => { const store = storage.getStore(); return store ? store.get(key) : undefined; }, }; module.exports = context;