UNPKG

logs-interceptor

Version:

High-performance, production-ready log interceptor for Node.js applications with Loki integration. Built with Clean Architecture principles. Supports Node.js, Browser, and Node-RED.

34 lines 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AsyncLocalStorageContextProvider = void 0; const async_hooks_1 = require("async_hooks"); class AsyncLocalStorageContextProvider { constructor() { this.asyncLocalStorage = new async_hooks_1.AsyncLocalStorage(); } getContext() { return this.asyncLocalStorage.getStore() ?? {}; } runWithContext(context, fn) { return this.asyncLocalStorage.run(context, fn); } async runWithContextAsync(context, fn) { return this.asyncLocalStorage.run(context, fn); } set(key, value) { const store = this.asyncLocalStorage.getStore(); if (store) { store[key] = value; } } get(key) { const store = this.asyncLocalStorage.getStore(); return store?.[key]; } clear() { // AsyncLocalStorage doesn't have a clear method // Context is cleared when the async context ends } } exports.AsyncLocalStorageContextProvider = AsyncLocalStorageContextProvider; //# sourceMappingURL=AsyncLocalStorageContextProvider.js.map