Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable logging to display Text objects with supported Styles #1751

Closed
jeremyschulman opened this issue Dec 11, 2021 · 5 comments
Closed

Enable logging to display Text objects with supported Styles #1751

jeremyschulman opened this issue Dec 11, 2021 · 5 comments

Comments

@jeremyschulman
Copy link

As 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.

@willmcgugan
Copy link
Collaborator

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 property markup. So it would be something like this in a logger:

logger.info(f"hello {name.markup}")

@jeremyschulman
Copy link
Author

@willmcgugan - that approach would be excellent, thank you!

@willmcgugan
Copy link
Collaborator

Hacked in that property. If you could give Rich 10.15.3a2 a try.

@willmcgugan
Copy link
Collaborator

That's in v10.16.0 now

@github-actions
Copy link

Did I solve your problem?

Consider sponsoring the ongoing work on Rich and Textual.

Or buy me a coffee to say thanks.

Will McGugan

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jan 5, 2022
10.16.2

Fixed

Fixed @ not being escaped in markup

10.16.1

Fixed

Fixed issues with overlapping tags Textualize/rich#1755

10.16.0

Fixed

Double print of progress bar in Jupyter Textualize/rich#1737

Added

Added Text.markup property Textualize/rich#1751
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants