Skip to content

Commit 7f22a9a

Browse files
improve error logging and request logging
1 parent 10c3741 commit 7f22a9a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

backend/src/middleware/auditLogger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ const logger = require('../util/logger')
44
const loggedMethods = ['POST', 'PUT', 'DELETE']
55

66
module.exports = function auditLogger(req, res, next) {
7-
console.log("Method: " + req.method)
8-
console.log("Time: " + new Date().toString())
7+
console.log("Req: " + req.method + " " + req.originalUrl + " at " + new Date().toString())
8+
console.log("body keys: " + Object.keys(req.body))
99
if (loggedMethods.includes(req.method)) {
1010
const type = `${req.method} ${req.originalUrl}`
1111

backend/src/util/errorHandler.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ module.exports = (err, req, res, next) => {
88
body: req.body,
99
stack: err.stack
1010
})
11+
console.log('Request error', {
12+
error: err.message,
13+
method: req.method,
14+
url: req.originalUrl,
15+
body: req.body,
16+
stack: err.stack
17+
})
1118

1219
res.status(500).send('Error')
1320
next()

0 commit comments

Comments
 (0)