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

Allow enable programmatically #416

Closed
dtomasi opened this issue Jan 25, 2017 · 4 comments
Closed

Allow enable programmatically #416

dtomasi opened this issue Jan 25, 2017 · 4 comments

Comments

@dtomasi
Copy link

dtomasi commented Jan 25, 2017

It would be nice to enable debug in browsers programmatically.

I would prefer something like that:

const debug = require('debug').enable('MyRootNamespace:MyServices:*');

// or for multiple namespaces
const debug = require('debug').enable(
   [
      'MyRootNamespace:MyServices:*',
      'MyRootNamespace:MyDataSources:*'
   ]
);

The solution to use localStorge does not work in Safari´s private mode anyway. Would be nice to have also the debug messages there ...

Also it would be nice to have the ability to deny enabling debug by setting localStorage.debug. The source code of my current project is only provided in a uglified version to protect my intellectual property and business secret. I don´t want anyone can enable debug information by setting localStorage.debug to '*'.

@vespakoen
Copy link

It also doesn't work in other runtimes that don't have localstorage (ExtendScript for example, a JS for controlling Adobe applications)

@dtomasi
Copy link
Author

dtomasi commented Feb 23, 2017

For those who can't wait, like me ;-)

I did a little change in my fork that allows to lately enable namespaces. see: https://github.com/dtomasi/debug/commit/f64af5669b2cb2184d99ac4d25cf4d216df78f2b

Within the initialization of my script I use something like that:

// Get the Module not the function it exposes
var debugModule = require('debug');
// Set storage to null. This stops the use of localStorage within my bundle
debugModule.storage = null;
// Disable all
debugModule.disable();

if (myConfig.debug) {
    debugModule.enable(myConfig.debug);
}

Cheers

@TooTallNate
Copy link
Contributor

@dtomasi We're heading towards dynamic debug instances in #440.

But tangentially related:

The source code of my current project is only provided in a uglified version to protect my intellectual property and business secret.

This is particularly frightening! Obscurity DOES NOT EQUAL security!!! If you have secret values or code then they should be secured behind server-side API calls, and not bundled with client-side code.

@TooTallNate
Copy link
Contributor

This now works in debug v3. Please open a new issue for any future troubles.

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

No branches or pull requests

3 participants