UNPKG

@ogma/nestjs-module

Version:

A NestJS module for the Ogma logger

40 lines (39 loc) 2.07 kB
import { CallHandler, ExecutionContext, NestInterceptor } from '@nestjs/common'; import { Reflector } from '@nestjs/core'; import { MonoTypeOperatorFunction, Observable } from 'rxjs'; import { OgmaService } from '../ogma.service'; import { InterceptorMeta } from './interfaces/interceptor-service.interface'; import { LogObject } from './interfaces/log.interface'; import { DelegatorService } from './providers'; /** * An interceptor to handle logging for just about any kind of request that Nest can handle */ export declare class OgmaInterceptor implements NestInterceptor { private readonly service; private readonly delegate; private readonly reflector; private json; private color; constructor(service: OgmaService, delegate: DelegatorService, reflector: Reflector); intercept(context: ExecutionContext, next: CallHandler): Observable<any>; rxJsLogTap(meta: InterceptorMeta): MonoTypeOperatorFunction<void>; shouldLogAndDoIt(method: 'Error' | 'Success', { context, startTime, data, correlationId, options }: InterceptorMeta & { data: any; }): void; /** * A method to determine if a request should be logged or not. This is determined by several factors: * 1) If `@OgmaSkip()` decorator is present on the class or the handler, the request should not be logged * 2) If the request is from a GQL subscription, it should not be logged * 3) if the request is for a contextType that does not have a parser installed and passed in the options, it should not be logged * @param context the execution context * @returns a boolean on if the request should not be logged */ shouldSkip(context: ExecutionContext): boolean; log(logObject: string | LogObject | unknown, context: ExecutionContext, correlationId?: string): void; /** * A method to generate a new correlationId on each request * @param _context The execution context object * @returns a string that represents the correlationId */ generateRequestId(_context?: ExecutionContext): string; }