Skip to content

Commit ffbbc46

Browse files
felixgery
authored andcommitted
Support inspecting objects with console.log
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.
1 parent 6cd32fb commit ffbbc46

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/node.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,15 @@ process.openStdin = function () {
192192
// console object
193193
var formatRegExp = /%[sdj]/g;
194194
function format (f) {
195+
if (typeof f !== 'string') {
196+
var objects = [], sys = module.requireNative('sys');
197+
for (var i = 0; i < arguments.length; i++) {
198+
objects.push(sys.inspect(arguments[i]));
199+
}
200+
return objects.join(' ');
201+
}
202+
203+
195204
var i = 1;
196205
var args = arguments;
197206
return String(f).replace(formatRegExp, function (x) {

0 commit comments

Comments
 (0)