Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow short-body to be excluded #47

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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