rich: [BUG] Should RichHandler default to stderr
Describe the bug
“Bug” is a little strong, but I noticed that by default Python logging writes to stderr, but when using RichHandler by default it writes to stdout.
I know you can get around this with something like:
logging.basicConfig(
level="DEBUG", datefmt="[%X]", handlers=[RichHandler(console=Console(stderr=True))]
)
But would it be more sensible and less surprising for new users if by default RichHandler logged to stderr?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 9
- Comments: 18 (5 by maintainers)
I also think that the RichHandler should not change default logger behaviour, ie. it should log to stderr by default.
Anyone using
RichHandleris already using python logging, and therefore expecting log output to go to stderr. It is more surprising for logging to not go to stderr.This is a bug, IMO.
For the record i am still holding my initial opinion that logging should default to stderr as it does normally with the logging module.
On Fri, Mar 15, 2024, at 4:04 PM, Simon Wiles wrote:
I’d also consider this a bug - lots (if not most) of CLI tools write errors and debug to
stderrwhile the (often parse-able) output goes tostdoutand might be piped to another tool, which now would have to guess whether a line is (optional) logging output, some error message or actual data it should process. E.g.:…would be quite hard to handle if every tool needed to know the (often flexible) logging format of it’s predecessor.
(This is true for every other (at least Posix based) tool I know, correct me if I’m wrong)
If you need both
stderrandstdoutyou can easily redirect them using e.g.2>&1. But without logging/error messages being sent tostderrthere is no trivial way to separate them.Agreed. Python logging defaults to stderr, and for a handler to change that contract without explicitly notifying users is a footgun waiting to be shot.
Lovely package, but I was getting invalid
jsonoutput for the reasons above. Pretty unexpected imo.This bug caused issues in my CLI app because logs were mixed with the app output and caused errors when piping. I feel that by default rich should avoid unexpected behaviour.
I just found that it seemed unexpected if python logging writes to stderr by default, I expected the Rich Handler to do the same. Isn’t that generally what one would expect? I might be wrong about that. I don’t think it’s a huge issue, but in my app I was piping the output somewhere and it’s nice for logging to not be mixed into the output stream if it’s a unix-y style terminal application.
On Wed, Mar 9, 2022, at 8:13 AM, Will McGugan wrote: