Does 'debug' cache the DEBUG environment variable somewhere? Getting no output after changing namespace and DEBUG env var.
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- electron, javascript, typescript
- Domain
- tooling
Research direction
Start by reproducing the namespace change from foo to bar in the debug initialization, checking how process.env.DEBUG is read and how log.enabled differs. Run the Electron Forge command with cross-env DEBUG=bar and compare output for both namespaces; done means the observed namespace behavior is explained and the issue is either resolved or clearly documented.
Written by the indexing model from the issue text.
Description
I am using 'debug' with TypeScript in an Electron project like so:
import debug from 'debug';
const log = debug('foo');
export default async function myFunction(name: string) {
log('calling myFunction');
...
log('successfully returning myFunction');
return someVariable;
}
in my shell (zsh) I set the DEBUG env var like so export DEBUG=foo and then started running my application. Everything worked fine. Eventually, I changed the namespace from foo to bar and now no matter what I do, I cannot get any output. I tried resetting DEBUG, I restarted my shell and set the environment variable again with export DEBUG=bar, I tried using the [cross-env]{https://www.npmjs.com/package/cross-env} to set it like so:
"scripts": {
"start": "tsc && cross-env DEBUG=bar NODE_ENV=development electron-forge start",
...
}
but nothing ever shows up.
I tried
import debug from 'debug';
const log = debug('bar');
console.log("DEBUG", process.env.DEBUG);
export default async function myFunction(name: string) {
log('calling myFunction');
...
log('successfully returning myFunction');
return someVariable;
}
and the console.log output is indeed: DEBUG bar.
The only way I can get it to work now is by doing:
import debug from 'debug';
const log = debug('bar');
log.enabled = true;
The moment I change const log = debug('bar'); back to const log = debug('foo'); , I get output messages for the foo namespace no matter what's in the DEBUG env var.
Any idea what might be happening here?
- Dominant language
- JavaScript
- Stars
- 11.5k
- Forks
- 992
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from debug-js/debug
-
Difficulty 1/5 Under an hour Newbie friendliness 82/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Debug as JSON Open
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 3/5 1-2 days Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 28/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·