Debug 訊息為什麼要輸出到 stderr?

3 分鐘閱讀

琳 avatar

在慣例中, debug message 會輸出在 stderr 中嗎?

Felo Search avatar
Felo Search

在慣例中,調試信息(debug messages)通常會輸出到標準錯誤流(stderr)中,而不是標準輸出流(stdout)。這種做法的主要原因是將調試信息與正常的程序輸出分開,以便於用戶能夠更清晰地識別和處理錯誤或診斷信息。

為什麼使用stderr而不是stdout?

總結來說,將調試信息輸出到stderr是一種廣泛接受的慣例,這樣做有助於提高程序的可維護性和可讀性。

  1. Write debug messages to stderr, not stdout · Issue #154 - GitHub

  2. Should I log messages to stderr or stdout? - Stack Overflow ↩2

  3. log levels and stdout vs stderr ↩2

  4. Alfred 3 Tip: Use stderr to output to the debug console

  5. How to Print to stderr and stdout in Python? - Flexiple