A Loguru sink that outputs logs to a Discord webhook.
Project description
loguru-discord-sink
A Loguru sink that outputs log messages to a Discord webhook.
Installation
pip install loguru-discord-sink
Quick setup
from loguru import logger
from loguru_discord_sink import DiscordWebhookSink
discord_webhook = "https://discord.com/api/webhooks/XXXX/XXXXX"
project_name = "my-service"
discord_sink = DiscordWebhookSink(discord_webhook, project_name)
logger.add(discord_sink, level="ERROR")
logger.info("This will not be sent.")
logger.error("Something failed!") # -> sent to Discord
[!WARNING]
This sink has no default filtering. If you don't specify a level or set up a filter when calling
logger.add(), Loguru will send all log messages to Discord. This includesDEBUG,INFO, etc, which will saturate your webhook.
Sink parameters
DiscordWebhookSink(
webhook_url: str,
project_name: str,
embed_colors: EmbedColors | None = None,
embed_titles: EmbedTitles | None = None,
discord_field_names: DiscordFieldNames | None = None
)
webhook_url: str
Discord webhook URL where messages will be forwarded to.
-
project_name: strProject name that will be used in the Discord default notification header. -
embed_colors: EmbedColors | NoneDictionary mapping to add custom colors to each Loguru log level.
colors = {
"ERROR": "16711680", # red
"SUCCESS": "65280", # green
}
[!NOTE]
Colors must be in decimal notation, as required by the Discord API.
embed_titles: EmbedTitles | None
Custom embed titles for each log level. project_name can be interpolated into these strings.
titles = {
"ERROR": "❌ {project_name} encountered an error",
"SUCCESS": "✅ {project_name} finished successfully",
}
discord_field_names: DiscordFieldNames | None
Titles for the fields shown inside the Discord embed
field_names = {
"level": "Severity",
"function": "Func",
"line": "Ln",
"file": "Path",
}
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_sink-0.1.2.tar.gz.
File metadata
- Download URL: loguru_discord_sink-0.1.2.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b90fba99400104f7eca95fcb35c06109d1611ce9ba4efba81f8e28479622513b
|
|
| MD5 |
99a2a3cb695fe6bee5db355dac454b79
|
|
| BLAKE2b-256 |
7551d37159f8985fe9aa680943421f360138c6009d148d261f40e91f42f9c923
|
File details
Details for the file loguru_discord_sink-0.1.2-py3-none-any.whl.
File metadata
- Download URL: loguru_discord_sink-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93417d302c61fe7b173132f147750ef92459a7f802eacb949af3d2e96403f14b
|
|
| MD5 |
11181e9a7dd39e3d836f0fc104a0f782
|
|
| BLAKE2b-256 |
984d7a9fd49a10a81b58370a094f6f2363215ffc05e926bd6f091f0e7dcac8d9
|