@ogma/nestjs-module
Version:
A NestJS module for the Ogma logger
93 lines (92 loc) • 4.14 kB
TypeScript
import { ArgumentsHost, HttpException } from '@nestjs/common';
import { Reflector } from '@nestjs/core';
import { OgmaInterceptorServiceOptions } from '../../interfaces/ogma-options.interface';
import { InterceptorService } from '../interfaces/interceptor-service.interface';
import { MetaLogObject } from '../interfaces/log.interface';
export declare abstract class AbstractInterceptorService implements InterceptorService {
protected readonly reflector: Reflector;
constructor(reflector: Reflector);
/**
* A method to transform the incoming execution context into metadata that the OgmaInterceptor will then log.
* This method handles the success cases
* @param data the response body that will be returned
* @param context the execution context from Nest
* @param startTime when the request started
* @param options the options passed to the interceptor
* @returns an object that represents what should be logged
*/
getSuccessContext(data: unknown, context: ArgumentsHost, startTime: number, options: OgmaInterceptorServiceOptions): MetaLogObject;
/**
* A method to transform the incoming execution context into metadata that the OgmaInterceptor will then log.
* This method handles the error cases
* @param error the error that happened
* @param context the execution context from Nest
* @param startTime when the request started
* @param options the options passed to the interceptor
* @returns an object that represents what should be logged
*/
getErrorContext(error: Error | HttpException, context: ArgumentsHost, startTime: number, options: OgmaInterceptorServiceOptions): MetaLogObject;
/**
* A helper method to get the status based on if the request was an error or success
* @param _context the execution context
* @param inColor if the status should be in color
* @param error if it was an error
* @returns a string representing the status
*/
getStatus(_context: ArgumentsHost, inColor: boolean, error?: HttpException | Error): string;
/**
* A helper method to allow devs the ability to pass in extra metadata when it comes to the interceptor
* @param _context The ArgumentsHost
* @param _data the response body or the error being returned
* @returns whatever metadata you want to add in on a second log line. This can be a string, an object, anything
*/
getMeta(_context: ArgumentsHost, _data: unknown): unknown;
/**
* A helper method to get the Ip of the calling client
* @param context the execution context
*/
abstract getCallerIp(context: ArgumentsHost): string[] | string;
/**
* A helper method to get the method type of the request
*
* REST: an HTTP Verb (GET, POST, PATCH, etc)
*
* GraphQL: Query, Mutation, or Subscription
*
* Microservice: Request or Reply
*
* Websockets: unknown at moment
*
* @param context the execution context
*/
abstract getMethod(context: ArgumentsHost): string;
private getResponseTime;
/**
* A helper method to get the protocol of the request
* @param context execution context from Nest
*/
abstract getProtocol(context: ArgumentsHost): string;
/**
* A helper method to get what was called
*
* REST: endpoint
*
* GraphQL: Query or Mutation name
*
* Microservice: Message Topic
*
* WebSockets: Subscription Event name
* @param context execution context from Nest
*/
abstract getCallPoint(context: ArgumentsHost): string;
/**
* A helper method for setting the correlationId to later be retrieved when logging
* @param context the execution context
* @param requestId the correlationId to set
*/
abstract setRequestId(context: ArgumentsHost, requestId: string): void;
abstract getRequestId(context: ArgumentsHost): string;
protected wrapInColor(status: number): string;
protected isBetween(comparator: number, bottom: number, top: number): boolean;
getStartTime(_host: ArgumentsHost): number;
}