UNPKG

@inward/extension-logging

Version:

LoopBack Logging for Winston and Fluentd

47 lines 2.01 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.InvocationLoggingInterceptor = void 0; const tslib_1 = require("tslib"); const context_1 = require("@inward/context"); const util_1 = require("util"); const keys_1 = require("../keys"); /** * A local interceptor that provides logging for method invocations. */ let InvocationLoggingInterceptor = /** @class */ (() => { let InvocationLoggingInterceptor = class InvocationLoggingInterceptor { constructor(logger) { this.logger = logger; } value() { return this.intercept.bind(this); } async intercept(invocationCtx, next) { try { this.logger.log('verbose', util_1.format('invoking %s with:', invocationCtx.targetName, invocationCtx.args)); const result = await next(); this.logger.log('verbose', util_1.format('returned from %s:', invocationCtx.targetName, result)); return result; } catch (err) { this.logger.log('error', util_1.format('error from %s', invocationCtx.targetName, err)); throw err; } } }; InvocationLoggingInterceptor = tslib_1.__decorate([ context_1.bind({ tags: { [context_1.ContextTags.KEY]: keys_1.LoggingBindings.WINSTON_INVOCATION_LOGGER }, scope: context_1.BindingScope.SINGLETON, }), tslib_1.__param(0, context_1.inject(keys_1.LoggingBindings.WINSTON_LOGGER)), tslib_1.__metadata("design:paramtypes", [Object]) ], InvocationLoggingInterceptor); return InvocationLoggingInterceptor; })(); exports.InvocationLoggingInterceptor = InvocationLoggingInterceptor; //# sourceMappingURL=logging.interceptor.js.map