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

Thomas Passin list1 at tompassin.net
Tue Jan 3 14:33:52 EST 2023


On 1/3/2023 11:51 AM, Stefan Ram wrote:
> Thomas Passin <list1 at tompassin.net> writes:
>> On 1/3/2023 10:35 AM, c.buhtz at posteo.jp wrote:
>> Also, I think it would be confusing to sometimes have logging output go
>> to stdout and other times go to stderr.
> 
>    In UNIX, the output of a program can be redirected,
>    so error messages written to the output might get appended
>    to some result file and might not be seen by the user.

Yes, and in Windows, too.  Note that stderr messages can be written or 
redirected to a file, too, and then would not be seen on the terminal.

>    Therefore, UNIX and C provide the unbuffered "stderr" stream
>    that can be redirected separately.
> 
>    The following example shows how logging might write to stdout.
> 
> import logging
> import sys
> logging.getLogger().addHandler( logging.StreamHandler( sys.stdout ))
> logging.error( 'example' )

This is starting to look too much like java.  Yuck!



More information about the Python-list mailing list