|
1 | | -var Transform = require('../common/transform.js'); |
| 1 | +var Transform = require('../common/transform.js'), |
| 2 | + util = require('util'); |
2 | 3 |
|
3 | | -function Stringify() {} |
| 4 | +function Stringify() { } |
4 | 5 |
|
5 | 6 | Transform.mixin(Stringify); |
6 | 7 |
|
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(' ')); |
30 | 16 | }; |
31 | 17 |
|
32 | 18 | module.exports = Stringify; |
0 commit comments