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

Uploaded Python 3

File details

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

File metadata

  • Download URL: logcord-0.1.1.tar.gz
  • Upload date:
  • Size: 5.4 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.1.tar.gz
Algorithm Hash digest
SHA256 7cac24831e7ca305d78889f5762e87485310251c77fb1f108f966ca4b1a9e2d7
MD5 b50a4d9f80befcc6b829686299aac54f
BLAKE2b-256 abcff7ec11098b246b521d7107152f78af002cc5a894750b325d88838d0d1ef8

See more details on using hashes here.

Provenance

The following attestation bundles were made for logcord-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: logcord-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.0 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2bdb31f69b2527e2c8aa48afe9b0f01cb96819785ab761562b3b1bf28c95730
MD5 b83372a3764020005427058db713fc37
BLAKE2b-256 a5d1755b1c340f36959db70b5f399ae8f2a0a350a466440402b33fc26744902a

See more details on using hashes here.

Provenance

The following attestation bundles were made for logcord-0.1.1-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