-
Notifications
You must be signed in to change notification settings - Fork 755
Open
Labels
questionFurther information is requestedFurther information is requested
Description
Description
When using RichHandler (from rich.logging) as a Loguru sink, tracebacks are not rendered as expected. Only the error message is displayed.
Environment
rich: v14.1.0
loguru: v0.7.3
Run the following minimal reproducible example:
from loguru import logger as logger1
import logging
from rich.logging import RichHandler
logger1.remove()
logger1.add(
RichHandler(
show_time=True,
show_level=True,
show_path=True,
enable_link_path=True,
log_time_format="[%Y-%m-%d %H:%M:%S]",
rich_tracebacks=True,
tracebacks_show_locals=True,
),
format=lambda _: "{message}",
level="DEBUG",
enqueue=True,
backtrace=False,
diagnose=False,
colorize=False,
)
logging.basicConfig(
level="DEBUG",
format="%(message)s",
datefmt="[%Y-%m-%d %H:%M:%S]",
handlers=[
RichHandler(
rich_tracebacks=True,
tracebacks_show_locals=True,
),
],
)
logger2 = logging.getLogger("rich")
def main(logger):
try:
logger.info("logging an info message")
x = 2 / 0
except Exception as e:
try:
raise Exception("This is an exception") from e
except Exception as se:
logger.exception(se)Calling main(logger2) (the standard logging version) correctly displays a rich-formatted traceback.
Log
[2025-10-24 11:19:59] INFO logging an info message test.py:40
ERROR This is an exception test.py:46
╭──────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────╮
│ test.py:41 in main │
│ │
│ 38 def main(logger): ╭──────────────────── locals ────────────────────╮ │
│ 39 │ try: │ e = ZeroDivisionError('division by zero') │ │
│ 40 │ │ logger.info("logging an info message") │ logger = <Logger rich (DEBUG)> │ │
│ ❱ 41 │ │ x = 2 / 0 │ se = Exception('This is an exception') │ │
│ 42 │ except Exception as e: ╰────────────────────────────────────────────────╯ │
│ 43 │ │ try: │
│ 44 │ │ │ raise Exception("This is an exception") from e │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
ZeroDivisionError: division by zero
The above exception was the direct cause of the following exception:
╭──────────────────────────────────────────────────────── Traceback (most recent call last) ─────────────────────────────────────────────────────────╮
│ test.py:44 in main │
│ │
│ 41 │ │ x = 2 / 0 ╭──────────────────── locals ────────────────────╮ │
│ 42 │ except Exception as e: │ e = ZeroDivisionError('division by zero') │ │
│ 43 │ │ try: │ logger = <Logger rich (DEBUG)> │ │
│ ❱ 44 │ │ │ raise Exception("This is an exception") from e │ se = Exception('This is an exception') │ │
│ 45 │ │ except Exception as se: ╰────────────────────────────────────────────────╯ │
│ 46 │ │ │ logger.exception(se) │
│ 47 │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Exception: This is an exception
But main(logger1) , i.e. loguru emits
[2025-10-24 11:22:17] INFO logging an info message test.py:40
ERROR This is an exception test.py:46
Exception: This is an exception
RichHandler subclasses logging.Handler, which means it is wrapped by Loguru’s StandardSink. It appears the issue may stem from Loguru’s formatter not passing exception info in the expected structure for RichHandler to render rich tracebacks, but I couldn’t confirm this.
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested