Loguru-Discord
Loguru-Discord is a lightweight sink for Loguru that forwards logs to Discord via the Webhook API.
Features
- 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
- Opt-in interception of standard library logging events, unified under Loguru
Getting Started
Installation
[!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
Handler
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 |
intercept |
Toggle whether to intercept standard library logging. | False |
intercept_level_map |
Map custom log levels to Loguru log levels. | None |
suppress |
List of Exception types to not forward to Discord. | None |
Example
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")
Releases
Loguru-Discord loosely follows Semantic Versioning for consistent, predictable releases.
Contributing
Contributions are welcome—whether it’s fixing bugs or adding new features.
- See
CONTRIBUTING.mdfor guidelines. - See Issues for known bugs and feature requests.
Acknowledgments
This project is not affiliated with or endorsed by Loguru or Discord in any way.
Release files for loguru-discord 2.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| loguru_discord-2.1.0.tar.gz | 113.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| loguru_discord-2.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 131.4 kB
Release files / loguru_discord-2.1.0.tar.gz
| Download URL | loguru_discord-2.1.0.tar.gz |
|---|---|
| Size | 113.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f386b616eb0f37ba5cba8567512d127b02f3120bffcfe83c86733d099e9a7e6
|
|
BLAKE2b-256 checksum How to use checksums |
554157bed0cc85eca3949f52e7595263d596ae16ec0ddd68cdca3d53d78a9ab7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / loguru_discord-2.1.0-py3-none-any.whl
| Download URL | loguru_discord-2.1.0-py3-none-any.whl |
|---|---|
| Size | 17.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
00d79e2575ee10ee01120c458f1f0e035bea2b6b106afcd2b9b05464abf4a39f
|
|
BLAKE2b-256 checksum How to use checksums |
3265a388c7bdd3c4d2e6009cb1298b2bd0f20ec1183d3bc31dd52867bc482969
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|