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.
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With