Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 54718d5

Browse files
author
Michal Vlasák
committed
Change express middleware format
1 parent 9b46f3e commit 54718d5

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

express.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const onFinished = require('on-finished');
22
const onHeaders = require('on-headers');
33

44
const expressMiddleware = function(req, response, next) {
5-
const reqInfo = `${req.method} ${req.originalUrl} HTTP/${req.httpVersion}`;
6-
this.debug({ req, ackId: req.ackId }, `${reqInfo} - Request accepted`);
5+
const reqIn = `--- ${req.method} ${req.originalUrl} ${req.headers['user-agent']}`;
6+
this.debug({ req, ackId: req.ackId }, `${reqIn} - Request accepted`);
77
req._startAt = process.hrtime();
88
onHeaders(response, () => {
99
response._startAt = process.hrtime();
@@ -14,15 +14,16 @@ const expressMiddleware = function(req, response, next) {
1414
});
1515
onFinished(response, (err, res) => {
1616
const error = res[Symbol.for('error')];
17+
const reqOut = `${res.statusCode} ${req.method} ${req.originalUrl} ${res.time} ms ${req.headers['user-agent']}`;
1718
if (this.options.ignoredHttpMethods.includes(req.method)) {
1819
return;
1920
}
2021
if (error) {
21-
this.error({ error, req, res, ackId: req.ackId }, `${reqInfo} - Error handler at the end of app`);
22+
this.error({ error, req, res, ackId: req.ackId }, `${reqOut} - Error handler at the end of app`);
2223
} else if (res.out) {
23-
this.debug({ req, res, ackId: req.ackId }, `${reqInfo} - Standard output [${res.statusCode}]`);
24+
this.debug({ req, res, ackId: req.ackId }, `${reqOut} - Standard output`);
2425
} else {
25-
this.info({ req, res, ackId: req.ackId }, `${reqInfo} - Standard output [${res.statusCode}]`);
26+
this.info({ req, res, ackId: req.ackId }, `${reqOut} - Standard output`);
2627
}
2728
});
2829
next();

0 commit comments

Comments
 (0)