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.
- Non-Blocking Execution: When you call
logger.info(), the handler immediately places the formatted message into a thread-safequeue.Queueand returns control to your application. - 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. - 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.
- Rate Limit Handling: If Discord returns a HTTP
429 Too Many Requestsstatus, the handler pauses execution for the exactretry_afterperiod 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cac24831e7ca305d78889f5762e87485310251c77fb1f108f966ca4b1a9e2d7
|
|
| MD5 |
b50a4d9f80befcc6b829686299aac54f
|
|
| BLAKE2b-256 |
abcff7ec11098b246b521d7107152f78af002cc5a894750b325d88838d0d1ef8
|
Provenance
The following attestation bundles were made for logcord-0.1.1.tar.gz:
Publisher:
publish.yml on hammadhassankhan05/logcord
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logcord-0.1.1.tar.gz -
Subject digest:
7cac24831e7ca305d78889f5762e87485310251c77fb1f108f966ca4b1a9e2d7 - Sigstore transparency entry: 977232421
- Sigstore integration time:
-
Permalink:
hammadhassankhan05/logcord@872a4601d4839279997ffe3f61186af6c57e581b -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/hammadhassankhan05
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@872a4601d4839279997ffe3f61186af6c57e581b -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2bdb31f69b2527e2c8aa48afe9b0f01cb96819785ab761562b3b1bf28c95730
|
|
| MD5 |
b83372a3764020005427058db713fc37
|
|
| BLAKE2b-256 |
a5d1755b1c340f36959db70b5f399ae8f2a0a350a466440402b33fc26744902a
|
Provenance
The following attestation bundles were made for logcord-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on hammadhassankhan05/logcord
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
logcord-0.1.1-py3-none-any.whl -
Subject digest:
b2bdb31f69b2527e2c8aa48afe9b0f01cb96819785ab761562b3b1bf28c95730 - Sigstore transparency entry: 977232454
- Sigstore integration time:
-
Permalink:
hammadhassankhan05/logcord@872a4601d4839279997ffe3f61186af6c57e581b -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/hammadhassankhan05
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@872a4601d4839279997ffe3f61186af6c57e581b -
Trigger Event:
release
-
Statement type: