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

Ability to control other options programatically #986

Open
lzilioli opened this issue Jan 15, 2025 · 0 comments
Open

Ability to control other options programatically #986

lzilioli opened this issue Jan 15, 2025 · 0 comments

Comments

@lzilioli
Copy link

I use the package dotenv and the dotenv.config(); function to load my config from a .env file. I would like my default .env file to contain the config:

DEBUG=my-app:*,-my-app:verbose*
DEBUG_COLORS=1

So that developers, with the default .env file will have a good experience.

I have found that I can get debug to honor my DEBUG environment variable with this snippet of code in my config file:

dotenv.config();
const DEBUG: false | string = process.env.DEBUG && process.env.DEBUG !== 'false' ? process.env.DEBUG : false;
if (isString(DEBUG) && DEBUG !== 'false') {
    console.error(colors.yellow(`🐞 enabling debug outout for: "${DEBUG}". You can edit, or disable this in the .env file`));
    Debug.enable(DEBUG);
}

but as far as I can tell, there is no way to get debug to switch the DEBUG_COLORS config over–once the package initializes and reads it from process.env, that's it. Unfortunately this doesn't work in this case.

Request: add a debug.init() method that can be called to re-read all of the environment configs–this way, once I know my environment is setup correctly, I can call debug.init and trust things will work.


I have run into the same exact issue with the debug package in the browser, though I did not know about debug.enableat the time. This point is moot, just wanted to provide it to share some insights with how I'm using it.

I have some FE code that says:

if (environment.local && !localStorage.debug) {
  localStorage.debug = '...';
  console.warn(`debug initialized–reload your browser and enable verbose logging in the console to see the output`);
}

In the front end case, I need to ship a change that uses debug.enable, and override the log to use console.log, and that will let me improve the experience.

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

1 participant