A lightweight sink for Loguru that forward logs to Discord via the Webhook API.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loguru_discord-2.1.0.tar.gz.
File metadata
- Download URL: loguru_discord-2.1.0.tar.gz
- Upload date:
- Size: 113.4 kB
- Tags: Source
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f386b616eb0f37ba5cba8567512d127b02f3120bffcfe83c86733d099e9a7e6
|
|
| MD5 |
d72f935d5eee0b9eabaa38d67e831d41
|
|
| BLAKE2b-256 |
554157bed0cc85eca3949f52e7595263d596ae16ec0ddd68cdca3d53d78a9ab7
|
File details
Details for the file loguru_discord-2.1.0-py3-none-any.whl.
File metadata
- Download URL: loguru_discord-2.1.0-py3-none-any.whl
- Upload date:
- Size: 17.9 kB
- Tags: Python 3
- Uploaded using 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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
00d79e2575ee10ee01120c458f1f0e035bea2b6b106afcd2b9b05464abf4a39f
|
|
| MD5 |
a2975067b736c019f8ff44bb62e2a22b
|
|
| BLAKE2b-256 |
3265a388c7bdd3c4d2e6009cb1298b2bd0f20ec1183d3bc31dd52867bc482969
|