Skip to content

Instantly share code, notes, and snippets.

@RReverser
Last active May 9, 2019 21:07
Show Gist options
  • Save RReverser/0a7caa89b465d1ed0c96 to your computer and use it in GitHub Desktop.
Save RReverser/0a7caa89b465d1ed0c96 to your computer and use it in GitHub Desktop.
Better console.log in Node
// UPD:
// Now available as npm module!
// Check out https://github.com/RReverser/better-log for details.
console.log = (function (log, inspect) {
return function () {
return log.apply(this, Array.prototype.map.call(arguments, function (arg) {
return inspect(arg, { depth: 1, colors: true });
}));
};
})(console.log, require("util").inspect);
@patik
Copy link

patik commented May 22, 2015

Really nifty. Just wanted to copy the screenshots from your tweet here to show what it does.

Before

After

@rajeshsegu
Copy link

JSON.stringify(obj, null, 2) so that it works both in browser as well as window

@RReverser
Copy link
Author

@rajeshsegu Um, JSON.stringify is completely irrelevant here, not sure why you posted it. It's not intended for debugging, fails on any recursive references, can't log a lot of object types such as RegExps, Dates etc., does not limit depth, does not colorize different types of literals and is just so much less functional than native console.log in browser or even in Node.js.

@SecComm
Copy link

SecComm commented May 24, 2015

Whaaaaat! That's awesome. I love the simplicity for such a genuinely helpful function. Thanks for sharing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment