Skip to content

no-loguru-exc-info

Loguru exc_info=True adds a field rather than retaining the exception traceback.

Why

Loguru accepts logging keyword arguments as structured fields. The standard logging exc_info=True argument therefore does not attach an exception, leaving failure logs without their traceback.

Fix

Use logger.opt(exception=True) or logger.exception(...) when reporting the active exception.

Examples

Before — flagged A standard logging argument does not capture the exception
app/service.py
from loguru import logger
try:
int("invalid")
except ValueError:
logger.warning("failed", exc_info=True)
After — preferred Loguru captures the exception through opt
app/service.py
from loguru import logger
try:
int("invalid")
except ValueError:
logger.opt(exception=True).warning("failed")