Permalink
Browse files

added Buffer support and updated test suite

  • Loading branch information...
1 parent 17e1569 commit f23eb98d91b0719eb45d0567d2f9faa0ae913275 @kilianc kilianc committed Jul 6, 2012
Showing with 21 additions and 5 deletions.
  1. +8 −5 console-trace.js
  2. +13 −0 test.js
View
13 console-trace.js
@@ -33,11 +33,14 @@ module.exports = function (options) {
;['error', 'log', 'info', 'warn', 'trace'].forEach(function (name) {
var fn = console[name];
console[name] = function () {
- if (console._trace || console.traceAlways) {
- if(typeof arguments[0] === 'object') {
- arguments[0] = JSON.stringify(arguments[0], null, ' ');
- }
- arguments[0] = console.traceFormat(__stack[1], name) + arguments[0];
+ if (console._trace || console.traceOptions.always) {
+ if (Buffer.isBuffer(arguments[0])) {
+ arguments[0] = arguments[0].inspect()
+ } else if (typeof arguments[0] === 'object') {
+ arguments[0] = JSON.stringify(arguments[0], null, ' ');
+ }
+ var pad = (arguments[0] && !console.traceOptions.right || !isatty ? ' ' : '');
+ arguments[0] = console.traceFormat(__stack[1], name) + pad + arguments[0];
}
console._trace = false;
return fn.apply(this, arguments);
View
13 test.js
@@ -60,3 +60,16 @@ require('./console-trace')({
process.stdout.write(' ');
console.traced[name]('this is a magenta traced console.' + name);
});
+
+process.stdout.write('\n---------------------------------------------------------\n\n');
+
+console.traceOptions.colors = true;
+
+process.stdout.write(' ');
+console.traced.log({ 1: 'works', 2: 'with', 3: 'Object' });
+
+process.stdout.write(' ');
+console.traced.log(['Works', 'with', 'Array']);
+
+process.stdout.write(' ');
+console.traced.log('Works with Buffer', Buffer('FooBar'));

0 comments on commit f23eb98

Please sign in to comment.