Enable logging to display Text objects with supported Styles
See original GitHub issueAs a developer of network infrastructure testing systems I use Rich to display progress of testing using the logging feature and display reports using the Table feature. In the same way that I use Text+Style to colorize my Tables, I would like to colorize/style text that is the logging output using the same Text/Style classes. Presently the logging feature supports the “markup” color notation exclusively.
This issue requests an enhancement so that I can pass Text objects to the logging log methods (info, error, warning, etc.) so that the output in the logs shows all color/styling that is supported by the Python logging infrastructure.
Example desired usage; assume the variable “logger” is a Rich python logger instance:
from rich.tex import Text, Style
name = Text("Jeremy", style=Style(color="blue"))
logger.info(f"Hello {name]")
The desired output would be “Hello Jeremy” with the text “Jeremy” colored blue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
@willmcgugan - that approach would be excellent, thank you!
It probably wouldn’t be quite as transparent as that. I wouldn’t want to change the output of
Text.__str__
at this point. I was thinking a propertymarkup
. So it would be something like this in a logger: