[GH-ISSUE #1160] Allow printing to stdout when log-file is not set (and command did not fail) #819

Open
opened 2026-05-07 00:27:45 +02:00 by BreizhHardware · 0 comments

Originally created by @0x07cf-dev on GitHub (Jul 26, 2024).
Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/1160

💡 Idea
Commands such as ntfy token list always write to stderr, even when return code is zero and therefore the execution succesful.

Reading through the logging section of the documentation, I found that if a logging file isn't specified (like in my case) then ntfy will start logging to the console, to stderr by default. But why shouldn't it log successful command outputs and results to stdout instead?

The relevant code appears to be on this line, for the token command.

Searching the repo for c.App.Writer yields two results, whereas c.App.ErrWriter appears to be widely and intentionally used.
As there could be important reasons for this to be the default behaviour, I am not creating a bug report / pull request.

I ran:

$ sudo ntfy token list unknown
user unknown does not exist
$ echo $?
1
$ sudo ntfy token list unknown 1>/dev/null
user unknown does not exist
$ sudo ntfy token list unknown 2>/dev/null
$

As you can see, listing tokens for non-existing users works as expected. It's an error, so the code 1 is returned and nothing is written to stdout.

On the other hand, listing tokens for existing users (or all tokens, for that matter) does not:

$ sudo ntfy token list phil
user phil
- tk_redacted1, ...
- tk_redacted2, ...
- tk_redacted3, ...
$ echo $?
0
$ sudo ntfy token list phil 1>/dev/null
user phil
- tk_redacted1, ...
- tk_redacted2, ...
- tk_redacted3, ...
$ sudo ntfy token list phil 2>/dev/null
$ 

💻 Target components
ntfy-cli

🔮 Additional context
ntfy 2.11.0 (d11b100), runtime go1.22.2

Originally created by @0x07cf-dev on GitHub (Jul 26, 2024). Original GitHub issue: https://github.com/binwiederhier/ntfy/issues/1160 <!-- Before you submit, consider asking on Discord/Matrix instead. You'll usually get an answer sooner, and there are more people there to help! - Discord: https://discord.gg/cT7ECsZj9w - Matrix: https://matrix.to/#/#ntfy:matrix.org / https://matrix.to/#/#ntfy-space:matrix.org --> :bulb: **Idea** Commands such as `ntfy token list` always write to stderr, even when return code is zero and therefore the execution succesful. Reading through the [logging section](https://docs.ntfy.sh/config/?h=stdout#logging-debugging) of the documentation, I found that if a logging file isn't specified (like in my case) then ntfy will start logging to the console, to stderr by default. But why shouldn't it log successful command outputs and results to stdout instead? The relevant code appears to be [on this line](https://github.com/binwiederhier/ntfy/blob/72f36f8296aec9c67a14dbff459e801d63084635/cmd/token.go#L203), for the token command. Searching the repo for `c.App.Writer` yields two results, whereas `c.App.ErrWriter` appears to be widely and intentionally used. As there could be important reasons for this to be the default behaviour, I am not creating a bug report / pull request. I ran: ``` $ sudo ntfy token list unknown user unknown does not exist $ echo $? 1 ``` ``` $ sudo ntfy token list unknown 1>/dev/null user unknown does not exist $ sudo ntfy token list unknown 2>/dev/null $ ``` As you can see, listing tokens for non-existing users works as expected. It's an error, so the code 1 is returned and nothing is written to stdout. On the other hand, listing tokens for existing users (or all tokens, for that matter) does not: ``` $ sudo ntfy token list phil user phil - tk_redacted1, ... - tk_redacted2, ... - tk_redacted3, ... $ echo $? 0 ``` ``` $ sudo ntfy token list phil 1>/dev/null user phil - tk_redacted1, ... - tk_redacted2, ... - tk_redacted3, ... $ sudo ntfy token list phil 2>/dev/null $ ``` :computer: **Target components** ntfy-cli :crystal_ball: **Additional context** ntfy 2.11.0 (d11b100), runtime go1.22.2
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/ntfy#819
No description provided.