mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-27 09:42:53 +00:00
22 lines
546 B
TypeScript
22 lines
546 B
TypeScript
import { Injectable, NestMiddleware, Logger } from "@nestjs/common";
|
|
import { Request, Response, NextFunction } from "express";
|
|
|
|
@Injectable()
|
|
export class LoggerMiddleware implements NestMiddleware {
|
|
private readonly logger = new Logger("HTTP");
|
|
|
|
use(req: Request, res: Response, next: NextFunction) {
|
|
const start = Date.now();
|
|
|
|
res.on("finish", () => {
|
|
const duration = Date.now() - start;
|
|
|
|
this.logger.log(
|
|
`${req.method} ${req.originalUrl} ${res.statusCode} ${duration}ms`,
|
|
);
|
|
});
|
|
|
|
next();
|
|
}
|
|
}
|