File tree Expand file tree Collapse file tree 1 file changed +9
-5
lines changed
Expand file tree Collapse file tree 1 file changed +9
-5
lines changed Original file line number Diff line number Diff line change 11import express from 'express' ;
22import { logger } from '../utils/logging' ;
33
4- export const RequestLogName = 'request' ;
5-
64export const logging = (
75 req : express . Request ,
86 res : express . Response ,
97 next : express . NextFunction ,
108) : void => {
11- res . on ( 'finish' , ( ) =>
9+ const startTime = process . hrtime ( ) ;
10+
11+ res . on ( 'finish' , ( ) => {
12+ const [ seconds , nanoseconds ] = process . hrtime ( startTime ) ;
13+ const responseTimeMs = seconds * 1000 + nanoseconds / 1e6 ;
14+
1215 logger . info ( {
1316 status : res . statusCode ,
1417 method : req . method ,
@@ -19,8 +22,9 @@ export const logging = (
1922 epicTargeting : res . locals . epicTargeting ,
2023 userAgent : isServerError ( res . statusCode ) ? req . headers [ 'user-agent' ] : undefined ,
2124 epicSuperMode : res . locals . epicSuperMode ,
22- } ) ,
23- ) ;
25+ responseTimeMs : responseTimeMs . toFixed ( 0 ) ,
26+ } ) ;
27+ } ) ;
2428 next ( ) ;
2529} ;
2630
You can’t perform that action at this time.
0 commit comments