question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable logging to display Text objects with supported Styles

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
jeremyschulmancommented, Dec 11, 2021

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

1reaction
willmcgugancommented, Dec 11, 2021

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}")
Read more comments on GitHub >

github_iconTop Results From Across the Web

Enable logging to display Text objects with supported Styles
This issue requests an enhancement so that I can pass Text objects to the logging log methods (info, error, warning, etc.) so that...
Read more >
Logging Cookbook — Python 3.11.1 documentation
As you can see, the DEBUG message only shows up in the file. ... Logging (as of 3.2) provides improved support for these...
Read more >
Logging | Apps Script - Google Developers
A basic approach to logging in Apps Script is to use the built-in execution log. To view these logs, at the top of...
Read more >
Python Logging Guide - Best Practices and Hands-on Examples
We will introduce various concepts relevant to understanding logging in Python, discuss the corresponding logging APIs in Python and how to use ...
Read more >
How to Style console.log Contents in Chrome DevTools - Telerik
This post demonstrates how to add CSS styling to the console output in ... up the text colors; here, let's see how we...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found