Merge pull request #375 from orangejulius/use_json_stringify
Use JSON.stringify to log objects
This commit is contained in:
@ -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();
|
||||
}
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user