Loguru-Discord is a lightweight sink for Loguru that forwards logs to Discord via the Webhook API.
- Plug-and-play adoption with your existing logging structure
- Highly configurable presentation, from usernames and avatars to rich formatting and truncation
- Fully type-hinted for an excellent developer experience
- Native and performant Webhook API interaction powered by Clyde
Important
Loguru-Discord requires Python 3.11 or later.
Install with uv (recommended):
uv add loguru-discord
Alternatively, install with pip:
pip install loguru-discord
You can integrate Loguru-Discord in just two lines:
from loguru_discord import DiscordSink
logger.add(DiscordSink("https://discord.com/api/webhooks/00000000/XXXXXXXX"))All configuration is handled on DiscordSink via optional keyword arguments.
| Argument | Description | Default |
|---|---|---|
webhook_url |
Discord Webhook URL to forward log events to. | N/A (Required) |
username |
String to use for the Webhook username. | None (Determined by Discord) |
avatar_url |
Image URL to use for the Webhook avatar. | None (Determined by Discord) |
rich |
Toggle whether to use Discord Components. | False |
suppress |
List of Exception types to not forward to Discord. | None |
Here’s a complete, end-to-end example using Loguru-Discord:
from loguru import logger
from loguru_discord import DiscordSink
# Construct the Discord handler
sink: DiscordSink = DiscordSink("https://discord.com/api/webhooks/00000000/XXXXXXXX")
# Add the sink to Loguru
logger.add(sink)
# Log an exception
try:
value: float = 1 / 0
except Exception as e:
logger.opt(exception=e).error("Lorem ipsum dolor sit amet")Loguru-Discord loosely follows Semantic Versioning for consistent, predictable releases.
Contributions are welcome—whether it’s fixing bugs or adding new features.
- See
CONTRIBUTING.mdfor guidelines. - See Issues for known bugs and feature requests.
This project is not affiliated with or endorsed by Loguru or Discord in any way.
