What should go to stdout/stderr and why Python logging write everything to stderr?

MRAB python at mrabarnett.plus.com
Tue Jan 3 11:36:53 EST 2023


On 2023-01-03 15:35, c.buhtz at posteo.jp wrote:
> Hello,
> 
> this posting isn't about asking for a technical solution. My intention
> is to understand the design decision Python's core developers made in
> context of that topic.
> 
> The logging module write everything to stderr no matter which logging
> level is used.
> 
> The argparse module does it more differentiated. If arguments are
> mandatory but none are given then argparse produce a short version of
> the usage info; on stderr. If the user request the usage info via "-h"
> it goes to stdout. This is the behavior I would expect.
> 
> Why does logging behave different? DEBUG and INFO imho should go to
> stdout not stderr.
> 
> Of course I could modify the handlers etc. to workaround this. But I
> assume that there was something in mind of the Python developers when
> they decided that.
> 
> My goal is not to divide between the use of print() or logging.info()
> in my own code. This would mess up a lot.

The purpose of stderr is to display status messages, logging and error 
messages, even user prompts, and not mess up the program's actual 
output. This is important on a *nix system where you might be piping the 
output of one program into the input of another.


More information about the Python-list mailing list