Skip to main content

A Loguru sink that outputs logs to a Discord webhook.

Project description

loguru-discord-sink

PyPI Python Versions License Ruff

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 includes DEBUG, 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: str Project name that will be used in the Discord default notification header.

  • embed_colors: EmbedColors | None Dictionary 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

loguru_discord_sink-0.1.3.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

loguru_discord_sink-0.1.3-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file loguru_discord_sink-0.1.3.tar.gz.

File metadata

  • Download URL: loguru_discord_sink-0.1.3.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for loguru_discord_sink-0.1.3.tar.gz
Algorithm Hash digest
SHA256 9b17e7341d48df5f06f9fb1d08225637dd91966ada4d609350731be324b8efbc
MD5 7737b16056e127a0b66d86f9430105b4
BLAKE2b-256 a40044ea44ac84a599ba0e7600eb9b617a25b43a560e21e87a11f059cf419e99

See more details on using hashes here.

File details

Details for the file loguru_discord_sink-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for loguru_discord_sink-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 38978ee9868c8d67bdfb8a3a419c6452fdb7f586dc2c889ddb61a4171f6bdf49
MD5 a03a1fdfd0adb597253b1000d3240785
BLAKE2b-256 b3005adc735e1f16e082ca26928bd77b25462b42d1f7bde7bad9b796527659bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page