Skip to content

Commit

Permalink
Add new logging middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Tooseriuz committed Jan 16, 2024
1 parent 1c167e1 commit 9b96d7a
Show file tree
Hide file tree
Showing 5 changed files with 333 additions and 267 deletions.
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16.19.1
20.9.0
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ And these services in `amazon` mode:

In production the API endpoints are run directly:
```
npm start:api
npm run start:api
```
and
```
npm start:tasks
npm run start:tasks
```

5. Open [localhost:3030/docs](http://localhost:3030/docs) to test the endpoints.
Expand Down
19 changes: 19 additions & 0 deletions middleware/logging.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const winston = require('winston')
const expressWinston = require('express-winston')

module.exports = expressWinston.logger({
transports: [
new winston.transports.Console()
],
format: winston.format.combine(
winston.format.simple()
),
meta: false,
msg: function (req, res) {
let body = Array.isArray(req.body) ? req.body : { ...req.body }

Check failure on line 13 in middleware/logging.js

View workflow job for this annotation

GitHub Actions / test

'body' is never reassigned. Use 'const' instead
const userEmail = (req.rfcx && req.rfcx.auth_token_info && req.rfcx.auth_token_info.email) ? req.rfcx.auth_token_info.email : 'none'
return `${req.method} ${res.statusCode} ${req.url} Response Time: ${res.responseTime} Authorization: ${req.headers.authorization} Email: ${userEmail} Body: ${JSON.stringify(body)}`
},
expressFormat: false,
statusLevels: true
})
Loading

0 comments on commit 9b96d7a

Please sign in to comment.