Skip to main content

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 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.1.tar.gz (5.7 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.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: loguru_discord_sink-0.1.1.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

Hashes for loguru_discord_sink-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8ec7eab874d9361026c1d3670af11bf8b0f288d9b45265547727adf5c5c4b1fb
MD5 f3a81f39c848d17eb6eac6aec3d1bcd2
BLAKE2b-256 bbbf620e4cbc974619b8a1e2b4775de16bc15d674d67262375b112a56dc46107

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for loguru_discord_sink-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1cbed9f1e9a4694eebed4dc8219ee3adec36edd7e660d3cc3dc0289f9cafbb17
MD5 8b74ba5ffd2f227d55a0103ee026b572
BLAKE2b-256 4e433bf031e4e21a1e91ccbcb97d3a85dc1168e03b4eccc7e8a19839a60a8f79

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