From cbeccfd636ec649422ee41e2f218f4a317408622 Mon Sep 17 00:00:00 2001 From: Matz Reckeweg Date: Tue, 19 Sep 2017 14:37:38 +0200 Subject: [PATCH] allow short-body to be excluded --- index.js | 4 ++-- test/bunyan.test.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 57ba297..97456c3 100644 --- a/index.js +++ b/index.js @@ -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, @@ -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); } diff --git a/test/bunyan.test.js b/test/bunyan.test.js index 8f73815..95570c6 100644 --- a/test/bunyan.test.js +++ b/test/bunyan.test.js @@ -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();