Skip to content

Commit

Permalink
improve error logging and request logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ShootingStar91 committed Aug 16, 2023
1 parent 10c3741 commit 7f22a9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/src/middleware/auditLogger.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const logger = require('../util/logger')
const loggedMethods = ['POST', 'PUT', 'DELETE']

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

Expand Down
7 changes: 7 additions & 0 deletions backend/src/util/errorHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ module.exports = (err, req, res, next) => {
body: req.body,
stack: err.stack
})
console.log('Request error', {
error: err.message,
method: req.method,
url: req.originalUrl,
body: req.body,
stack: err.stack
})

res.status(500).send('Error')
next()
Expand Down

0 comments on commit 7f22a9a

Please sign in to comment.