Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use without monkey-patching core #1

Open
Fishrock123 opened this issue May 17, 2015 · 3 comments
Open

Use without monkey-patching core #1

Fishrock123 opened this issue May 17, 2015 · 3 comments

Comments

@Fishrock123
Copy link

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 nodejs/node#1716, and think a good userland solution might be better than adding this sort of functionality to core. :)

@Rich-Harris
Copy link
Owner

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
Copy link

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
Copy link

momocow commented Jan 15, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants