You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am wondering if there is any way to prevent this tedious and overly redundant inizialization in each module:
require('debug').enable('module-name:log module-name:ERROR');
var log = require('debug')('module-name:log');
var error = require('debug')('module-name:ERROR');
As you can see it's redundant on two different levels: I need to "enable" the loggers before instantiating them, sending the same name twice as strings, and I need to write the module name. Is there any way to do this automagically?
I could be wrong, but you may be missing the point slightly; debug shouldn't merely be treated as a drop-in-replacement for console.log with pretty colours, albeit it can be, if you enable all output, i.e. export DEBUG="*" for node.js environments and debug.enable("*") for browsers.
The power of debug is really in being able to see only targeted output, instead of trying to find the correct lines in a torrent of text whizzing by. That's where namespacing and module names come to your aid.
However, to answer you question:
I tend to use browserify for bundling, enabling/disabling output in my entry point file. Combined with envify it becomes a breeze to enable or disable debug output in the same manner for all environments. (I.e. using environment variables during runtime/build time.)
Hi @stablum, I've just replied to your stackoverflow question. If you are using debug outside the browser you can use debug-logger to lazily instantiate multiple instances of debug to log at different levels as you would do with console. It's essentially a wrapper for debug with no other dependencies.
Example:
varlog=require('debug-logger')('myapp');log.trace("I'm a trace output");log.debug("I'm a debug output");log.log("I'm a log output");log.info("I'm an info output");log.warn("I'm a warn output");log.error("I'm an error output");
Activity
[-]node.js' debug module: how to avoid this tedious initialization?[/-][+]how to avoid the tedious initialization?[/+]ibc commentedon Nov 16, 2014
That is how the module is designed. Anyhow take a look to #156
nikcorg commentedon Nov 18, 2014
I could be wrong, but you may be missing the point slightly;
debugshouldn't merely be treated as a drop-in-replacement forconsole.logwith pretty colours, albeit it can be, if you enable all output, i.e.export DEBUG="*"for node.js environments anddebug.enable("*")for browsers.The power of
debugis really in being able to see only targeted output, instead of trying to find the correct lines in a torrent of text whizzing by. That's where namespacing and module names come to your aid.However, to answer you question:
I tend to use
browserifyfor bundling, enabling/disabling output in my entry point file. Combined withenvifyit becomes a breeze to enable or disable debug output in the same manner for all environments. (I.e. using environment variables during runtime/build time.)dmarcelino commentedon Mar 11, 2015
Hi @stablum, I've just replied to your stackoverflow question. If you are using
debugoutside the browser you can use debug-logger to lazily instantiate multiple instances ofdebugto log at different levels as you would do with console. It's essentially a wrapper fordebugwith no other dependencies.Example:
would print:
More info at the project page,
Regards
ashwell commentedon Oct 6, 2016
I know this is a year later, but I just wrote this to help facilitate creating debug instances for stdout and stderr...
threw that in a
utilsfolder and require/use it just like you would debug, just with a little added destructuring magicthebigredgeek commentedon Dec 14, 2016
Closing this for now. Feel free to discuss further the V3 API RFC issue: #370