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

[REQUEST] Markup=True when configuring logging RichHandler #171

Closed
ewels opened this issue Jul 23, 2020 · 4 comments
Closed

[REQUEST] Markup=True when configuring logging RichHandler #171

ewels opened this issue Jul 23, 2020 · 4 comments

Comments

@ewels
Copy link
Contributor

ewels commented Jul 23, 2020

How would you improve Rich?

The Rich logging is really nice to use, however I must admit that having to add extra={"markup": True} on loads of log calls bloats the code a bit.

Would it be possible to make this an option in rich.logging.RichHandler() as well, so that this could be enabled by default for all log messages when configuring the logger?

For example, something like:

import logging
from rich.console import Console
from rich.logging import RichHandler

logging.basicConfig(
    level="NOTSET",
    format="%(message)s",
    datefmt="[%X]",
    handlers=[RichHandler(
        file=Console(file=sys.stderr),
        markup=True    ### New option
    )]
)

log = logging.getLogger("rich")
log.info("Hello, World!")

log.error("[bold red blink]Server is shutting down![/]")
# Instead of:
# log.error("[bold red blink]Server is shutting down![/]", extra={"markup": True})
@willmcgugan
Copy link
Collaborator

The extra arg is kind of ugly.

I wasn't keen on enabling markup in the handler, because log messages can come from libraries not under your control. If you enable logging for a dependency and that lib writes a log message containing square brackets then the contents of the square brackets will be removed or result in an unwanted style.

That said, I could add that option to RichHandler as you suggested, with a prominent warning in the docs...

@ewels
Copy link
Contributor Author

ewels commented Jul 23, 2020

Yes exactly - I figured that was the case and I agree it makes sense not to have it turned on by default. The extra arg is also fine if you only need it once or twice. It's just if you really want to pimp all of your log messages everywhere that it starts being a problem 😅

@willmcgugan
Copy link
Collaborator

Added the markup parameter in v4.0.0

@ewels
Copy link
Contributor Author

ewels commented Jul 23, 2020

Ok, that was silly fast. You haven't even triaged the issue yet and you've already pushed a release with the new feature 😆

Amazing stuff, thank you!!

ewels added a commit to ewels/nf-core-tools that referenced this issue Jul 23, 2020
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