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

Already on GitHub? Sign in to your account

Parse process.env when debug is called rather than when it is required. #61

Closed
danielchatfield opened this Issue Aug 24, 2013 · 2 comments

Comments

Projects
None yet
2 participants

Currently the environment variable is parsed when debug is required, this means that if the module wants to dynamically change the environment (for example in the presence of a --debug argument) then the require has to be done after this logic instead of at the top of the file, as is convention.

I think it would be better to parse the environment variable when debug() is first called as then modules which would like the extra flexibility can do the following and it will work with the modified env.

var debug = require('debug');

// environment changing logic

debug = debug('module');
Owner

TooTallNate commented Jun 1, 2014

I'd entertain a pull request.

This might be nice actually from a clean logic perspective since right now both node.js and browser.js manually invoke the "enable" and "save" functions. In theory, we could migrate that logic to the common debug.js file.

Owner

TooTallNate commented Jun 1, 2014

Closing for now though, since I don't think it's something we'll get around to without a patch in front of us.

Additionally, the "delayed" logic can be defeated: consider a module that instantiates a debug instance and invokes it before returning, making it so that your code still can't register a DEBUG env variable in time.

debug.enable() sounds like it would be more up your alley.

@TooTallNate TooTallNate closed this Jun 1, 2014

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