UNPKG

@interaktiv/mibuilder-core

Version:

Core libraries to interact with MiBuilder projects.

67 lines (52 loc) 1.81 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.Memory = void 0; var _winston = _interopRequireDefault(require("winston")); // Ensure we have the correct winston here. if (Number(_winston.default.version.split('.')[0]) < 3) { throw new Error('winston-memory requires winston >= 3.0.0'); } /** * Inherit from `winston-transport` so you can take advantage of the base * functionality and `.exceptions.handle()`. */ class Memory extends _winston.default.Transport { constructor(options = {}) { super(options); // // Consume any custom options here. e.g.: // - Connection information for databases // - Authentication information for APIs (e.g. loggly, papertrail, // logentries, etc.). // // Expose the name of this Transport on the prototype this.name = options.name || 'memory'; this.limit = options.limit || 100; this.records = []; } /** * Core logging method exposed to Winston. * * @param {Object} info - All relevant log information * @param {Function} next - Continuation to respond to when complete. */ log(info, next) { // Emit the `logged` event immediately because the event loop // will not exit until `process.stdout` has drained anyway. setImmediate(() => this.emit('logged', info)); if (this.silent) { next(); return; } this.records.push(info); if (this.records.length > this.limit) this.records.shift(); // Perform the writing to the remote service next(); } } // // Define a getter so that `winston.transports.Memory` // is available and thus backwards compatible. // exports.Memory = Memory; _winston.default.transports.Memory = Memory;