Skip to main content

A lightweight, thread-safe logging handler for sending Python logs to Discord via webhooks.

Project description

Discord Webhook Logger 📝👾

A lightweight, thread-safe Python logging handler that streams your application logs directly to a Discord channel using Webhooks.

Perfect for monitoring background tasks, web scrapers, automated pipelines, or server alerts without needing heavy monitoring infrastructure.

Installation

pip install logcord

How It Works Under the Hood

The DiscordWebhookHandler is designed to have zero impact on your main application's performance.

  1. Non-Blocking Execution: When you call logger.info(), the handler immediately places the formatted message into a thread-safe queue.Queue and returns control to your application.
  2. Background Processing: A daemon thread runs in the background, waking up every flush_interval (default 3 seconds) to pull all pending logs from the queue.
  3. Smart Batching & Chunking: The background worker stitches multiple short logs together into a single message to minimize HTTP requests. If a single log (like a massive traceback) exceeds Discord's character limit, it automatically chunks it into multiple sequential messages.
  4. Rate Limit Handling: If Discord returns a HTTP 429 Too Many Requests status, the handler pauses execution for the exact retry_after period requested by Discord before continuing, ensuring no logs are dropped.

Usage: Dual Logging

For production scripts like web scraping pipelines, automated pricing tools, or forecasting systems, you typically want to log to the console for local debugging, while sending only critical warnings and errors to Discord.

Here is how you configure the handler to only forward WARNING level and above to Discord:

import os
from logcord import setup_logger, shutdown_logs

# 1. Setup logger using simple strings
webhook_url = os.environ.get("DISCORD_WEBHOOK_URL")
logger = setup_logger(
    name="AutomationApp", 
    webhook_url=webhook_url,
    console_level="DEBUG",
    discord_level="ERROR"
)

# 2. Use standard logging methods directly
logger.info("Script started.")
logger.error("Something went wrong!")

# 3. Call logcord's custom shutdown wrapper
shutdown_logs()

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

logcord-0.1.0.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

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

logcord-0.1.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file logcord-0.1.0.tar.gz.

File metadata

  • Download URL: logcord-0.1.0.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for logcord-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ec280932fb54e2d7152dea2548741a5a9a6c195cd5f2b00817d855bf454898f8
MD5 250b2906a1bfcf50fb687fe29f642a31
BLAKE2b-256 fe83cbf1fca2df5559c1eee685e28e0da8798dd8599009154c77e822091b5a24

See more details on using hashes here.

Provenance

The following attestation bundles were made for logcord-0.1.0.tar.gz:

Publisher: publish.yml on hammadhassankhan05/logcord

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file logcord-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: logcord-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for logcord-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9469485e8e2f3b7307592eefa3b157d9ecbbc092f9c91ea26ab6ec95efde9e36
MD5 82dd06a5e575ba1d300c9e2c9e969599
BLAKE2b-256 9d29853f6b768eddcc95d064b1aad4a68713be152e01abae701b687effedcd75

See more details on using hashes here.

Provenance

The following attestation bundles were made for logcord-0.1.0-py3-none-any.whl:

Publisher: publish.yml on hammadhassankhan05/logcord

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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