-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: access log, optional validity count
- Loading branch information
1 parent
6f02090
commit ab29692
Showing
3 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const util = require('node:util'); | ||
|
||
const LOG_FORMAT = '%s %s "%s %s HTTP/%s" %d %s %s[ms]'; | ||
|
||
module.exports = async (ctx, next) => { | ||
const t0 = performance.now(); | ||
await next(); | ||
const t1 = performance.now(); | ||
try { | ||
ctx.accessLogger.debug(util.format( | ||
LOG_FORMAT, | ||
ctx.ip, | ||
ctx.method, | ||
`${ctx.path}${ctx.search}`, | ||
ctx.req.httpVersion, | ||
ctx.status, | ||
ctx.length ? ctx.length.toString() : '-', | ||
(t1 - t0).toFixed(3) | ||
) | ||
); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; |
This file contains 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