-
-
Save r37r0m0d3l/d9987f63ea4c8e3e71911408874cb35d to your computer and use it in GitHub Desktop.
Simplest Morgan NestJS Middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable, MiddlewareFunction, NestMiddleware } from '@nestjs/common'; | |
import * as morgan from 'morgan'; | |
import { LoggerService } from './mylogger'; | |
@Injectable() | |
export class MorganMiddleware implements NestMiddleware { | |
constructor(private readonly logger: LoggerService) {} | |
resolve(): MiddlewareFunction { | |
return morgan('combined', { | |
stream: { write: str => this.logger.info(str) }, | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment