Merge pull request #375 from orangejulius/use_json_stringify

Use JSON.stringify to log objects
This commit is contained in:
Spencer
2016-07-06 16:27:39 -06:00
committed by GitHub
2 changed files with 8 additions and 2 deletions

View File

@ -182,7 +182,7 @@ Log.parseLevels = function (input) {
Log.join = function (arrayish) {
return _.map(arrayish, function (item) {
if (_.isPlainObject(item)) {
return _.inspect(item) + '\n';
return JSON.stringify(item, null, 2) + '\n';
} else {
return item.toString();
}

View File

@ -97,7 +97,13 @@ describe('Log class', function () {
expect(Log.join(['foo', 'bar'])).to.eql('foo bar');
});
it('stringifies objects', function () {
expect(Log.join([{ foo: 'bar' }])).to.eql('{ foo: \'bar\' }\n');
expect(Log.join([{ foo: 'bar' }])).to.eql('{\n "foo": "bar"\n}\n');
});
it('fully stringifies deeply nested objects', function() {
var object = { foo: { bar: { baz: 'value' } } };
var expected = '{\n "bar": {\n "baz": "value"\n }\n}\n';
expect(Log.join(object)).to.eql(expected);
});
});