Skip to content

Commit

Permalink
allow short-body to be excluded
Browse files Browse the repository at this point in the history
  • Loading branch information
m-reckeweg committed Sep 19, 2017
1 parent 9586ccf commit cbeccfd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ module.exports.errorLogger = function (opts) {
'referer': referer,
'user-agent': ua,
'body': req.body,
'short-body': undefined,
'short-body': true,
'http-version': httpVersion,
'response-time': responseTime,
"response-hrtime": hrtime,
Expand Down Expand Up @@ -175,7 +175,7 @@ module.exports.errorLogger = function (opts) {
}

// Set the short-body here in case we've modified the body in obfuscate
if (json && json.body) {
if (json && json.body && json['short-body'] === true) {
json['short-body'] = util.inspect(json.body).substring(0, 20);
}

Expand Down
28 changes: 28 additions & 0 deletions test/bunyan.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,34 @@ describe('bunyan-logger', function() {
});
});

it('test excludes short-body', function(done) {
var app = express();
var output = st();

app.use(require('body-parser').json());

app.use(bunyanLogger({
stream: output,
excludes: ['short-body']
}));

app.post('/', function(req, res) {
res.send('POST /');
});

request(app)
.post('/')
.send("content")
.expect('POST /', function(err, res) {
var json = JSON.parse(output.content.toString());
assert.equal(json.name, 'express');
assert.equal(json.url, '/');
assert.equal(json['status-code'], 200);
assert(json.body);
assert(!json['short-body']);
done();
});
});

it('test excludes all', function(done) {
var app = express();
Expand Down

0 comments on commit cbeccfd

Please sign in to comment.