You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Very broad exception handling because it's always better to
# fall back to non-colored logs than to break at startup.
pass
returnFalse
The LogFormatter might be able to be attached to a handler which is not writing to stderr type stream, but to some other TTY-capable device, which I have in my case. The syserr TTY test prevents attaching the LogFormatter to such logger handler and having color support.
If I monkey-patch _stderr_supports_color() to lambda: True, and make sure I make a call to curses.setupterm(fd=...), passing the fd of my TTY-capable stream, then I can log with the color support from LogFormatter, which is nice.
Maybe the best fix is to change color: True to None, but default based on the detection above, or if set to True explicitly by the caller, honour that.
The text was updated successfully, but these errors were encountered:
Yeah, making the color argument three-valued (with None meaning "auto") seems like the way to go. That'll require a little refactoring to split the detection part of _stderr_supports_color from the initialization part, but that seems like a good idea anyway.
Now that I'm rereading the curses docs, it looks like we should also be passing stderr's file descriptor to curses.setupterm (otherwise it may send terminal escape characters to the wrong stream if stderr and stdout have different destinations).
LogFormatter
:tornado/tornado/log.py
Line 81 in c447875
... has very nice support for color logging via
curses
(orcolorama
).My issue is with the test
sys.stderr.isatty()
in:tornado/tornado/log.py
Lines 55 to 71 in c447875
The
LogFormatter
might be able to be attached to a handler which is not writing tostderr
type stream, but to some other TTY-capable device, which I have in my case. Thesyserr
TTY test prevents attaching theLogFormatter
to such logger handler and having color support.If I monkey-patch
_stderr_supports_color()
tolambda: True
, and make sure I make a call tocurses.setupterm(fd=...)
, passing thefd
of my TTY-capable stream, then I can log with the color support fromLogFormatter
, which is nice.Maybe the best fix is to change
color: True
toNone
, but default based on the detection above, or if set toTrue
explicitly by the caller, honour that.The text was updated successfully, but these errors were encountered: