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.

[REQUEST] Demo how to work in conjunction with `loguru`

See original GitHub issue

Have you checked the issues for a similar suggestions? Yes

How would you improve Rich?

Loguru is kind of a wrapper around the logging library. I’ve seen in your docs that you can pass the RichHandler() to logging to generate “rich” logs.

https://loguru.readthedocs.io/en/stable/api/logger.html#loguru._logger.Logger.configure

However in my current project, we are using loguru, so I’m trying to figure out how to do a similar thing (if it’s even possible), to pass RichHandler() to loguru, so I can generate these rich logs that are great.

It would be great if you could explain if this is possible, and if so share how it works, perhaps appending this detail to the rich docs here.

My naive attempt at getting this to work:

from loguru import logger
from rich.logging import RichHandler

logger.configure(handlers=[RichHandler()])
logger.debug("This is a debug statement")
logger.info("This is an info statement")

But I get fairly confused with the traceback. Hoping you may be able to enlighten me!

What problem does it solved for you?

It would enable me to use rich formatting on logs in conjunction with the loguru package. Perhaps other users of loguru would be interested in this as well.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10

github_iconTop GitHub Comments

2reactions
willmcgugancommented, Jul 20, 2020

Haven’t used loguru before, but I got it working with Rich. You were close, the configure method takes a list of dicts.

from loguru import logger
from rich.logging import RichHandler

logger.configure(handlers=[{"sink":RichHandler(), "format":"{message}"}])
logger.debug("This is a debug statement")
logger.info("This is an info statement")

Only thing I couldn’t figure out was how to change loguru date format.

0reactions
ughstudioscommented, Oct 15, 2022

This did not work for me 😦

Read more comments on GitHub >

github_iconTop Results From Across the Web

[REQUEST] Demo how to work in conjunction with loguru #163
Haven't used loguru before, but I got it working with Rich. You were close, the configure method takes a list of dicts. from...
Read more >
A Complete Guide to Logging in Python with Loguru
The most basic way to use Loguru is by importing the logger object from the loguru package. This logger is pre-configured with a...
Read more >
The Python loguru Library - July 26, 2019 - YouTube
Python Users Group meeting recording from July 26, 2019An explanation and demonstration of loguru. We also address some users issues with ...
Read more >
A quick guide to using Loguru - Medium
Loguru allows debugging python programs a lot easier. ... If you plan to use Loguru in a production environment, be careful of using...
Read more >
Loguru: Python Logging Made (stupidly) Simple - Morioh
Loguru is a library which aims to bring enjoyable logging in Python. ... To use Loguru from inside a library, remember to never...
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