Rich-Harris / node-console-group

console.group() for node.js
41 stars 3 forks source link

Use without monkey-patching core #1

Open Fishrock123 opened 9 years ago

Fishrock123 commented 9 years ago

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. :)

Rich-Harris commented 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!

kenbellows commented 7 years ago

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.

momocow commented 6 years ago

FYI

Colors.js is also a library patching the console to make it more colorful. They also provide a safe way to use the library, i.e., a wrapper of all patched methods, without modifying the original console object.

Anyway, nice work of this module. :)