UNPKG

@rxap/nest-open-api

Version:

This package provides tools and utilities for integrating OpenAPI specifications into NestJS applications. It includes features for handling upstream API requests, managing server configurations, and generating OpenAPI documentation. It also offers interc

52 lines (51 loc) 2.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.LoggingInterceptor = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const rxjs_1 = require("rxjs"); let LoggingInterceptor = class LoggingInterceptor { intercept(context, next) { const classType = context.getClass(); if (classType.name === 'HealthController') { return next.handle(); } if (classType.name === 'AppController') { return next.handle(); } const request = context.switchToHttp().getRequest(); const requestId = (function randomNum() { return Math.floor(Math.random() * 9999999).toFixed(0).padStart(7, '0'); })(); this.logger.debug(`[${requestId}] ${request.method.toUpperCase()} ${request.url}`, classType.name); if (request.body) { this.logger.verbose(`[${requestId}] REQUEST ${JSON.stringify(request.body)}`, classType.name); } const now = Date.now(); return next .handle() .pipe((0, rxjs_1.tap)({ next: (body) => { this.logger.debug(`[${requestId}] SUCCESS ${request.method.toUpperCase()} ${request.url} +${Date.now() - now}ms`, classType.name); if (body) { this.logger.verbose(`[${requestId}] RESPONSE ${JSON.stringify(body)}`, classType.name); } else { this.logger.verbose(`[${requestId}] RESPONSE <empty>`, classType.name); } }, error: (error) => { this.logger.debug(`[${requestId}] FAILURE ${error.message} ${request.url} +${Date.now() - now}ms`, classType.name); }, })); } }; exports.LoggingInterceptor = LoggingInterceptor; tslib_1.__decorate([ (0, common_1.Inject)(common_1.Logger), tslib_1.__metadata("design:type", common_1.Logger) ], LoggingInterceptor.prototype, "logger", void 0); exports.LoggingInterceptor = LoggingInterceptor = tslib_1.__decorate([ (0, common_1.Injectable)() ], LoggingInterceptor);