forked from mtusi2026/mtusi2026lab3
[+] Completed lab 3
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { NextFunction, Request, Response } from 'express';
|
||||
import { logger } from '../config/logger';
|
||||
|
||||
export function requestLogger(
|
||||
req: Request,
|
||||
res: Response,
|
||||
next: NextFunction,
|
||||
): void {
|
||||
const started = process.hrtime.bigint();
|
||||
res.once('finish', () => {
|
||||
const elapsedMs = Number(process.hrtime.bigint() - started) / 1_000_000;
|
||||
logger.info(
|
||||
{
|
||||
request_id: res.locals.requestId,
|
||||
method: req.method,
|
||||
path: req.path,
|
||||
status: res.statusCode,
|
||||
duration_ms: Math.round(elapsedMs * 100) / 100,
|
||||
},
|
||||
'request completed',
|
||||
);
|
||||
});
|
||||
next();
|
||||
}
|
||||
Reference in New Issue
Block a user