Open Fishrock123 opened 9 years ago
The trouble is that you then can't capture console.log
messages that you don't generate yourself - e.g.
var console = require( 'groupable-console' );
var doSomethingThatUsesConsoleLog = require( 'some-module' );
console.group();
console.log( 'this will be indented' );
doSomethingThatUsesConsoleLog({ verbose: true }); // is not indented!
console.groupEnd();
I can't think really think of a way around that. Also, when debugging a library with many files, you want to be able to quickly throw a few console.log
messages here and there without having to require a separate module at the top of each file (for one thing, using the console
global causes jshint to shout at you, which means you're less likely to accidentally leave them in...). Shoving require('console-group').install()
at the top of your test suite is more convenient IMHO.
That said, if you have any ideas to make it work I'm all ears!
How about offering a method to return a console wrapper object as an optional alternative to .install()
for folks who don't mind the extra effort or the downsides? Go ahead and leave .install()
in there as-is, but it would be cool if I could do something like var logger = require('console-group').wrapper()
when I want to. I mean, go ahead and fill up the docs with caveats and warnings so everyone is aware of the issues you mentioned above, but even with all that in mind, it would definitely be a nice feature.
In the interest to make userland modules better overall, would it be possible to export the function in a way which does not require overwriting core console methods?
Was linked to this module by https://github.com/nodejs/io.js/issues/1716, and think a good userland solution might be better than adding this sort of functionality to core. :)