UNPKG

@linkedmink/multilevel-aging-cache

Version:

Package provides an interface to cache and persist data to Redis, MongoDB, memory

44 lines (43 loc) 1.52 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Logger = void 0; const winston_1 = __importDefault(require("winston")); /** * Expose the logger constructor, so that output can be customized */ class Logger { static get options() { return Logger.optionsValue; } /** * Change the options before constructing a logger. A logger will use the options * set at the time the first get() is called for a specific label */ static set options(options) { Logger.optionsValue = options; } /** * Wrap the Winston logger container, so we can get the same logger for each module. * @param label The label of the module we're logging * @return An instance of the logger */ static get(label = Logger.GLOBAL_LABEL) { if (!winston_1.default.loggers.has(label)) { winston_1.default.loggers.add(label, Logger.optionsValue); } return winston_1.default.loggers.get(label); } } exports.Logger = Logger; Logger.GLOBAL_LABEL = 'AppGlobalLogger'; // Set default to console since we need at least one transport, should override in actual app Logger.options = { transports: [ new winston_1.default.transports.Console({ format: winston_1.default.format.simple(), }), ], };