UNPKG

logctx

Version:

A Pino-based logger with context-aware logging using async_hooks

31 lines (30 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WithLogger = void 0; const ContextualLogger_1 = require("./ContextualLogger"); const sharedLogger = new ContextualLogger_1.ContextualLogger(); /** * A decorator that adds a logger to the class. * The logger can be accessed via the `log` property. * @returns A class decorator that adds a logger to the class. */ // eslint-disable-next-line @typescript-eslint/no-explicit-any function WithLogger() { return function (OriginalClass) { return class extends OriginalClass { constructor(...args) { super(...args); if (!('log' in this)) { Object.defineProperty(this, 'log', { get() { return sharedLogger.log; }, configurable: false, enumerable: false, }); } } }; }; } exports.WithLogger = WithLogger;