-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(logging): write only specific fields for user logging (#81)
- Loading branch information
1 parent
e157128
commit a2b0116
Showing
2 changed files
with
12 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
const morgan = require('morgan'); | ||
const _ = require('lodash'); | ||
|
||
const log = require('./logger'); | ||
|
||
module.exports = morgan((tokens, req, res) => { | ||
const user = req.user | ||
? _.pick(req.user, ['id', 'username', 'first_name', 'last_name', 'email']) | ||
: undefined; | ||
|
||
const body = _.isEmpty(req.body) | ||
? undefined | ||
: req.body; | ||
|
||
log.info({ | ||
method: tokens.method(req, res), | ||
url: tokens.url(req, res), | ||
status: tokens.status(req, res), | ||
length: tokens.res(req, res, 'content-length'), | ||
'response-time': tokens['response-time'](req, res), | ||
user: req.user, | ||
body: req.body | ||
user, | ||
body | ||
}, 'Request processed'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters