nestjs-context-winston
Version:
Contextual Logger for nestjs apps using AsyncLocalStorage and winston
22 lines (21 loc) • 1.11 kB
TypeScript
import { ExecutionContext, HttpStatus } from '@nestjs/common';
import { BaseContextLogger } from './base-context-logger';
import { Logform } from 'winston';
import { LogLevel } from 'winston-context-logger';
import type { FastifyReply, FastifyRequest } from 'fastify';
import type { Request, Response } from 'express';
export type ContextFilter = (context: ExecutionContext) => boolean;
export type HttpRequest = FastifyRequest | Request;
export type HttpResponse = FastifyReply | Response;
export interface ContextLoggingOptions<TLogger extends BaseContextLogger<object> = BaseContextLogger<object>> {
statusCodeCallback?(err: unknown): number;
logClass: new (...args: ConstructorParameters<typeof BaseContextLogger<object>>) => TLogger;
errorLevelCallback?: (error: unknown) => HttpStatus;
getCorrelationId?: () => string | undefined;
logEnricher?: Logform.FormatWrap;
httpEnrich?: (req: HttpRequest, res: HttpResponse) => Record<string, unknown>;
useLogInterceptor?: boolean;
logLevel?: LogLevel;
contextFilter?: ContextFilter;
contextData?: Array<new () => object>;
}