What should go to stdout/stderr and why Python logging write everything to stderr?
Thomas Passin
list1 at tompassin.net
Thu Jan 5 08:31:40 EST 2023
On 1/5/2023 6:27 AM, Peter J. Holzer wrote:
> On 2023-01-04 12:32:40 -0500, Thomas Passin wrote:
>> On 1/3/2023 10:35 AM, c.buhtz at posteo.jp wrote:
>>> The logging module write everything to stderr no matter which logging
>>> level is used.
>>
>> The OP wrote this, but it's not so by default.
>
> By default it is - sort of.
>
> That is all log messages go to stderr, but not all log levels are
> logged.
Actually, I misread something else that made me think that non-warning
messages would go to stdout, but I was mistaken. As it happens, the
page in the Python docs only mention stderr twice, both in the same
paragraph:
"logging.lastResort
A “handler of last resort” is available through this attribute. This is
a StreamHandler writing to sys.stderr with a level of WARNING, and is
used to handle logging events in the absence of any logging
configuration. The end result is to just print the message to sys.stderr."
Nowhere else on this page is the printed output destination mentioned,
except that it gets printed on the console, which could be either stderr
or stdout.
The logging system is so configurable that a user could set a different
destination for each level of logging. So it seems that the O.P.'s
original question about why the package's developers choose stderr for
all levels can be answered: "They didn't".
More information about the Python-list
mailing list