UNPKG

@neoma/logging

Version:
37 lines (36 loc) 1.56 kB
import { NestMiddleware } from "@nestjs/common"; import { NextFunction, Request, Response } from "express"; import { LoggerService } from "@nestjs/common"; import { RequestLoggerService } from "@lib/services"; /** * Extends the Request object to include an optional logger property. */ declare module "express" { interface Request { logger?: LoggerService; } } /** * Piece of middleware that adds a {@link RequestLoggerService} instance to the incoming {@link Request} * * Note: It is sensible to install this piece of middleware as the first thing on Application start, that way * the {@link RequestLoggerService} is installed onto the {@link Request} as early as possible. */ export declare class RequestLoggerMiddleware implements NestMiddleware<Request, Response> { readonly logger: RequestLoggerService; /** * Constructs a RequestLoggerMiddleware instance with the {@link RequestLoggerService} that will be * attached to incoming {@link Request}s * * @param {RequestLoggerService} logger - The {@link RequestLoggerService} to install on the {@link Request} object. */ constructor(logger: RequestLoggerService); /** * Installs the {@link RequestLoggerService} onto the {@link Request} at req.logger. * * @param req - The received {@link Request}. * @param _res - The current {@link Response}. * @param next - Called once the {@link RequestLoggerService} is installed onto the {@link Request}. */ use(req: Request, _res: Response, next: NextFunction): void; }