Does 'debug' cache the DEBUG environment variable somewhere? Getting no output after changing namespace and DEBUG env var.

Ouverte
#901 6 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
À clarifier
Activité
À l'abandon
Stack technique
electron, javascript, typescript
Domaine
tooling

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

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?

Langage dominant
JavaScript
Étoiles
11.5k
Forks
992
Métriques de merge des PR
Aucune PR mergée en 30 j

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de debug-js/debug

Toutes les issues de debug-js/debug

Issues similaires

Plus d'issues JavaScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.