Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Python logging writes to stderr by default?

Related to Does Python logging write to stdout or stderr by default? but I want to know WHY it defaults to stderr instead WHAT is the default.

For me it isn't really obvious why stderr is the default. I noticed that something is wrong when I run python script.py | tee out.log and ended up with empty log file. Now I know that It can be solved by either python script.py 2>&1 | tee out.log or using stream parameter:

logging.basicConfig(stream=sys.stdout)

After that event it seems reasonable to me to change default stream to stdout in each script to avoid being surprised again. Is that a good practice? Will I miss something?

like image 867
WloHu Avatar asked Nov 29 '25 13:11

WloHu


1 Answers

You probably don't want to change the default to stdout. The reason for that is stderr is meant to be an output for all messages that are just some internal and/or debugging program information like logs and errors, rather than actual output, the result of the program.

like image 134
monomonedula Avatar answered Dec 02 '25 01:12

monomonedula



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!