UNPKG

@inward/extension-logging

Version:

LoopBack Logging for Winston and Fluentd

71 lines 2.66 kB
"use strict"; // Copyright IBM Corp. 2019. All Rights Reserved. // Node module: @inward/extension-logging // This file is licensed under the MIT License. // License text available at https://opensource.org/licenses/MIT Object.defineProperty(exports, "__esModule", { value: true }); exports.WinstonLoggerProvider = exports.WINSTON_FORMAT = exports.WINSTON_TRANSPORT = void 0; const tslib_1 = require("tslib"); const core_1 = require("@inward/core"); const winston_1 = require("winston"); /** * Re-export logform/winston types */ var logform_1 = require("logform"); Object.defineProperty(exports, "WinstonFormat", { enumerable: true, get: function () { return logform_1.Format; } }); var winston_2 = require("winston"); Object.defineProperty(exports, "format", { enumerable: true, get: function () { return winston_2.format; } }); Object.defineProperty(exports, "WinstonTransports", { enumerable: true, get: function () { return winston_2.transports; } }); /** * An extension point for winston transports */ exports.WINSTON_TRANSPORT = 'logging.winston.transport'; /** * An extension point for winston formats */ exports.WINSTON_FORMAT = 'logging.winston.format'; /** * A provider class that creates WinstonLogger instances */ let WinstonLoggerProvider = /** @class */ (() => { let WinstonLoggerProvider = class WinstonLoggerProvider { constructor( /** * Getter for transports */ transports, /** * Getter for formats */ formats, /** * Configuration for the logger */ options = {}) { this.transports = transports; this.formats = formats; this.options = options; } async value() { let transports = await this.transports(); if (transports.length === 0) { transports = [new winston_1.transports.Console({})]; } const formats = await this.formats(); return winston_1.createLogger({ transports, format: winston_1.format.combine(...formats), ...this.options, }); } }; WinstonLoggerProvider = tslib_1.__decorate([ tslib_1.__param(0, core_1.extensions(exports.WINSTON_TRANSPORT)), tslib_1.__param(1, core_1.extensions(exports.WINSTON_FORMAT)), tslib_1.__param(2, core_1.config()), tslib_1.__metadata("design:paramtypes", [Function, Function, Object]) ], WinstonLoggerProvider); return WinstonLoggerProvider; })(); exports.WinstonLoggerProvider = WinstonLoggerProvider; //# sourceMappingURL=winston.js.map