Support inspecting objects with console.log
authorFelix Geisendörfer <felix@debuggable.com>
Thu, 5 Aug 2010 09:38:11 +0000 (11:38 +0200)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 5 Aug 2010 17:23:17 +0000 (10:23 -0700)
If the first parameter passed into console.log() is not a string, all
parameters will be printed as formated by sys.inspect. This change
also affects console.info and console.warn.

src/node.js

index 70a291739aa9a223e12a55e841ae5f95f8c2c2f1..d512dc44c61b216794727e8bd6d1170bc1237e70 100644 (file)
@@ -192,6 +192,15 @@ process.openStdin = function () {
 // console object
 var formatRegExp = /%[sdj]/g;
 function format (f) {
+  if (typeof f !== 'string') {
+    var objects = [], sys = module.requireNative('sys');
+    for (var i = 0; i < arguments.length; i++) {
+      objects.push(sys.inspect(arguments[i]));
+    }
+    return objects.join(' ');
+  }
+
+
   var i = 1;
   var args = arguments;
   return String(f).replace(formatRegExp, function (x) {