Skip to main content

A logging handler that outputs logs to a Discord webhook.

Project description

log2discord

PyPI Python Versions License Ruff

A logging handler that outputs log messages to a Discord webhook.

Installation

pip install log2discord

Quick setup

Loguru

from loguru import logger
from log2discord import DiscordLoggingHandler

discord_webhook = "https://discord.com/api/webhooks/XXXX/XXXXX"
project_name = "my-service"

discord_sink = DiscordLoggingHandler(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

DiscordLoggingHandler(
    webhook_url: str,
    project_name: str,
    embed_colors: EmbedColors | None = None,
    embed_titles: EmbedTitles | None = None,
    mentioned_users: list[str] | None = None,
    mentioned_roles: list[str] | 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",
}
  • mentioned_users: list[str] List of User IDs that will be mentioned in each message.

  • mentioned_roles: list[str] List of Role IDs that will be mentioned in each message.

  • 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

log2discord-1.0.4.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

log2discord-1.0.4-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file log2discord-1.0.4.tar.gz.

File metadata

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

File hashes

Hashes for log2discord-1.0.4.tar.gz
Algorithm Hash digest
SHA256 9681bb31efad2ac4a34b4284e2d1a7a452cb3338a9b50d30516ee13c1f7ccafa
MD5 05c359cdf5e39e43fe5c1267b716ee41
BLAKE2b-256 6215c605690f0ca71235fcb6a24c2302e787b70f31bd89f351705b51e2569b0a

See more details on using hashes here.

File details

Details for the file log2discord-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: log2discord-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 7.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for log2discord-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ca0b05f721448c437b8cd4e9f6eceb9a389cae3f9c5559b98536ad493d352ae2
MD5 02ca487a8d295cce669f3005b72550ad
BLAKE2b-256 a32ea14791b6872cca020bdcf9676cf8c59eb2251adbd8ffe16f8d69977f94a6

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