Skip to content

Commit 87f5185

Browse files
committed
show timestamp as well
1 parent aefab74 commit 87f5185

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

backend/src/app.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ function logBodyGen(prependStr: string, getBodyFunc: (req: any, res: any) => str
3030
const method = req.method
3131
const status = res.statusCode
3232
const body = getBodyFunc(req, res)
33-
return `${method} ${url} ${status} ${prependStr}: ${JSON.stringify(body)}`
33+
const timeStamp = new Date().toISOString()
34+
return `[${timeStamp}] ${method} ${url} ${status} ${prependStr}: ${JSON.stringify(body)}`
3435
})
3536
return bodyFormatName
3637
}
@@ -44,8 +45,9 @@ appResponsePrototype.send = function sendOverWrite(body: any) {
4445
this[morganBodyResponseSymbol] = body
4546
}
4647

47-
app.use(morgan(logBodyGen("Request", (req) => req.body)))
48-
app.use(morgan(logBodyGen("Response", (_req, res) => res[morganBodyResponseSymbol])))
48+
app.use(morgan("[:date[iso]] :method :url :status ResponseTime :response-time ms"))
49+
app.use(morgan(logBodyGen("RequestBody", (req) => req.body)))
50+
app.use(morgan(logBodyGen("ResponseBody", (_req, res) => res[morganBodyResponseSymbol])))
4951

5052
app.get("/", (_req, res) => {
5153
res.status(200).send("Hello, world!")

0 commit comments

Comments
 (0)