Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should GUI application warning messages be sent to std::cerr?

Should a Unix GUI application's warning be sent to std::cerr or std::cout?

This presumes that GUI normally presents the warnings and errors in a console window and also sends them to a log file. But in the case that the console is missing and thus cannot be used should std::cerr, std::cout, or std::clog be used for such messages?

I'm thinking std::cerr is where they belong.

like image 682
WilliamKF Avatar asked Dec 21 '22 22:12

WilliamKF


2 Answers

I prefer cerr. If the user pipes the output or sends it to a file, they can opt-out of cerr with

tool 2>/dev/null >output

but putting everything in one stream leaves them SOL.

Also cerr is unbuffered, so error messages are guaranteed to appear no matter how hard you crash and burn. And warnings should be piped along with errors, if the user replaced /dev/null above with something else… I'm not sure if that's a distinct argument or not.

like image 191
Potatoswatter Avatar answered Jan 05 '23 15:01

Potatoswatter


If your program is designed to have a properly formatted output that may be piped to another program, or is going to be parsed, you should better redirect warnings to std::cerr.

like image 36
Benoit Avatar answered Jan 05 '23 15:01

Benoit