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

Commit bbc51bb

Browse files
author
Michal Vlasák
committed
Merge branch 'feature/add-req-info-to-debug-messages' into 'master'
Add req info to debug messages See merge request Backend/ackee-node-logger!2
2 parents be85c0f + 99456d3 commit bbc51bb

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
coverage
3+
4+
.idea/*

express.js

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

44
const expressMiddleware = function(req, response, next) {
5-
this.debug({ req, ackId: req.ackId }, 'Request accepted');
5+
const reqInfo = `${req.method} ${req.originalUrl} HTTP/${req.httpVersion}`;
6+
this.debug({ req, ackId: req.ackId }, `${reqInfo} - Request accepted`);
67
req._startAt = process.hrtime();
78
onHeaders(response, () => {
89
response._startAt = process.hrtime();
@@ -14,11 +15,11 @@ const expressMiddleware = function(req, response, next) {
1415
onFinished(response, (err, res) => {
1516
const error = res[Symbol.for('error')];
1617
if (error) {
17-
this.error({ error, req, res, ackId: req.ackId }, 'Error handler at the end of app');
18+
this.error({ error, req, res, ackId: req.ackId }, `${reqInfo} - Error handler at the end of app`);
1819
} else if (res.out) {
19-
this.debug({ req, res, ackId: req.ackId }, `Standard output [${res.statusCode}]`);
20+
this.debug({ req, res, ackId: req.ackId }, `${reqInfo} - Standard output [${res.statusCode}]`);
2021
} else {
21-
this.info({ req, res, ackId: req.ackId }, `Standard output [${res.statusCode}]`);
22+
this.info({ req, res, ackId: req.ackId }, `${reqInfo} - Standard output [${res.statusCode}]`);
2223
}
2324
});
2425
next();

0 commit comments

Comments
 (0)