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

オープン
#901 コメント 6 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
electron, javascript, typescript
領域
tooling

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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?

主要言語
JavaScript
スター
11.5k
フォーク
992
PR マージ指標
30日以内にマージされた PR はありません

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

debug-js/debug のほかの issue

debug-js/debug の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。