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

Đang mở
#901 6 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
electron, javascript, typescript
Lĩnh vực
tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
JavaScript
Star
11.5k
Fork
992
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của debug-js/debug

Tất cả issue của debug-js/debug

Issue tương tự

Thêm issue về JavaScript

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.