Skip to content

Commit 2e3bb8d

Browse files
committed
Fixed clean formatter and stringify.js. Now it can output objects too
1 parent 26b7400 commit 2e3bb8d

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

lib/node/formatters/clean.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
var Transform = require('../../common/transform.js');
22

3-
function FormatClean() {}
3+
function FormatClean() { }
44

55
Transform.mixin(FormatClean);
66

7-
FormatClean.prototype.write = function(name, level, args) {
8-
function pad(s) { return (s.toString().length == 1? '0'+s : s); }
9-
this.emit('item', (name ? name + ' ' : '') + (level ? level + ' ' : '') + args.join(' '));
7+
FormatClean.prototype.write = function (name, level, args) {
8+
function pad(s) { return (s.toString().length == 1 ? '0' + s : s); }
9+
this.emit('item', (name ? name + ' ' : '') + (level ? level + ' ' : '') +
10+
args.map(function (item) {
11+
return (typeof item == 'string' ? item : util.inspect(item, null, 3, true));
12+
}).join(' '));
1013
};
1114

1215
module.exports = FormatClean;

lib/node/stringify.js

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,18 @@
1-
var Transform = require('../common/transform.js');
1+
var Transform = require('../common/transform.js'),
2+
util = require('util');
23

3-
function Stringify() {}
4+
function Stringify() { }
45

56
Transform.mixin(Stringify);
67

7-
Stringify.prototype.write = function(name, level, args) {
8-
var result = [];
9-
if(name) result.push(name);
10-
if(level) result.push(level);
11-
result = result.concat(args);
12-
for(var i = 0; i < result.length; i++) {
13-
if(result[i] && typeof result[i] == 'object') {
14-
// Buffers in Node.js look bad when stringified
15-
if(result[i].constructor && result[i].constructor.isBuffer) {
16-
result[i] = result[i].toString();
17-
} else {
18-
try {
19-
result[i] = JSON.stringify(result[i]);
20-
} catch(stringifyError) {
21-
// happens when an object has a circular structure
22-
// do not throw an error, when printing, the toString() method of the object will be used
23-
}
24-
}
25-
} else {
26-
result[i] = result[i];
27-
}
28-
}
29-
this.emit('item', result.join(' ') + '\n');
8+
Stringify.prototype.write = function (name, level, args) {
9+
this.emit('item', (name ? name + ' ' : '') + (level ? level + ' ' : '') +
10+
args.map(function (item) {
11+
return (typeof item == 'string' ? item : util.inspect(item, {
12+
depth: 3,
13+
colors: false
14+
}));
15+
}).join(' '));
3016
};
3117

3218
module.exports = Stringify;

0 commit comments

Comments
 (0)