tornadoweb / tornadoweb/tornado
LogFormatter: allow color support when sys.stderr.isatty() == False
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 22.2k
- Forks
- 5.6k
- Avg merge
- 3h 42m
- Merged PRs (30d)
- 16
Description
LogFormatter:
https://github.com/tornadoweb/tornado/blob/c447875a1058f4768c2995ddd9ebb0eaddd3f32e/tornado/log.py#L81
... has very nice support for color logging via curses (or colorama).
My issue is with the test sys.stderr.isatty() in:
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in tornado/log.py at LogFormatter and _stderr_supports_color(), then review the existing stderr TTY check and the caller-provided color option. Compare how curses.setupterm(fd=...) is used for a TTY-capable stream. Done means an explicitly enabled color formatter can work with a non-stderr TTY without regressing default detection.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100