Replies: 1 comment
-
|
Thinking about it, it may actually be a bit more difficult. People might also want to use markdown in the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey.
With
rich.logging.RichHandlerthere's themarkup=parameter which defaults however for good reason toFalse.Also one can use
extra={"markup": True}in an actual log message (like vialogging.error(...)).While this allows fine control over specifically sending a log message with
rich’s markup it still has, AFAICS, one problem.The
msgparameter of theloggingcall will now contain the markup and that may also be picked up by any other handlers.Often these handlers are configurable by the user via some config file.
What one wants however, is that only
RichHandlergets the markup version and all others the non-markup version.Basically I see to ways to get this:
richcould provide it’s own derived version ofLoggerwhere it overrides the logic and strips the markup for any except its own handler.The downside of this is that people would have to use the derived
Logger, which brings all kinds of issues (e.g. people might want to makerichan optional dependency).rich_markup_msgas anextrafield, which onlyRichHandlerwould pick up and, if given, use instead ofmsg(it could of course also do the string interpolation using the*args, just onrich_markup_msg=.People would the need to call like:
logger.error("This is a SERIOUS error code %s!", error_code, extra={"rich_markup_msg": "This is a [bold red blink]serious[/] error code %s!"}Now while the doubling of the message is ugly on the one hand, it’s also a chance on the other, since one might want to use a different string in case
richisn’t used, like above where I wrote theSERIOUSthat would be used by non-RichHandler-handlers in capital letters.Cheers,
Chris.
PS: I’d suggest to prefix the
extrafield withrich_so that other handlers are less likely to pick it up by accident. The same should IMO have been done withmarkupwhich is a pretty generic term.Beta Was this translation helpful? Give feedback.
All reactions