Discord Logging Handler
A Python logging handler that sends log messages to Discord via webhook with colour-coded levels.
Features
- Colour-coded embeds by log level
- Supports full stack traces for errors and exceptions
- Configurable minimum log level
- Simple drop-in integration for any Python project
- Optional development mode to suppress logs during builds/tests
Installation
pip install discord-logging-handler
Usage
from discord_logging_handler import DiscordWebHookHandler
import logging
handler = DiscordWebHookHandler(webhook_url="WEBHOOK_URL", level=logging.INFO, dev_mode=True)
webhook_url: Your webhook from Discord Integrations.level(optional): The minimum level that should trigger logs to be sent to Discord. Defaults toERROR.dev_mode(optional): Use to enable development mode (logs are suppressed during builds/tests). Defaults toFalse.
Example
from discord_logging_handler import DiscordWebHookHandler
import logging
# Create handler
handler = DiscordWebHookHandler(webhook_url="WEBHOOK_URL", level=logging.INFO, dev_mode=False)
# Set up the root logger
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
logger.addHandler(handler)
# Example log messages
logger.info("Server started successfully.")
logger.warning("Disk space running low.")
logger.error("Database connection failed.")
# Example exception handling
try:
1 / 0
except Exception:
logger.exception("An unexpected error occurred.")
Example Output
Logs appear directly in your Discord channel with level-based colour coding:
Django Example
settings.py
import os
from pathlib import Path
from discord_logging_handler import DiscordWebHookHandler # ensure it's installed
BASE_DIR = Path(__file__).resolve().parent.parent
DISCORD_WEBHOOK_URL = os.environ.get('DISCORD_WEBHOOK_URL')
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'file': {
'level': 'INFO',
'class': 'logging.FileHandler',
'filename': BASE_DIR / 'logs/app.log',
'formatter': 'verbose',
},
'console': {
'class': 'logging.StreamHandler',
'formatter': 'simple'
},
'discord': {
'level': 'INFO',
'class': 'discord_logging_handler.handler.DiscordWebHookHandler',
'webhook_url': DISCORD_WEBHOOK_URL,
'dev_mode': False
}
},
'root': {
'handlers': ['console', 'file', 'discord'],
'level': 'INFO',
},
'loggers': {
'django': {
'handlers': ['console', 'file'],
'level': 'CRITICAL',
'propagate': True,
},
'vaultapi': {
'handlers': ['console', 'file', 'discord'],
'level': 'INFO',
'propagate': False,
},
},
}
Environment Variable
DISCORD_WEBHOOK_URL: Your Discord webhook URL.
Discord Webhook Setup
Discord allows webhooks to be created via Server Settings → Integrations.
- Go to Server Settings → Integrations
- Under Webhooks, click New Webhook
- Copy the generated webhook URL
Changelog
See the full Changelog for details on version history.
Contributing
Contributions, issues, and feature requests are welcome!
Feel free to open an issue or submit a pull request on GitHub.
License
MIT License
Copyright (c) 2025 Moses White
Metadata
Release files for discord-logging-handler 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| discord_logging_handler-0.3.1.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| discord_logging_handler-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 7.7 kB
Release files / discord_logging_handler-0.3.1.tar.gz
| Download URL | discord_logging_handler-0.3.1.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
950d8663f1ffd080f96f4e183394277eb6a3a0e494834d8d6fccacadba649abd
|
|
BLAKE2b-256 checksum How to use checksums |
8d91e63434c5554844ea7f57ff49a5f22203bf60c377e170cf4f0f0f8f7eb445
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.6
|
Release files / discord_logging_handler-0.3.1-py3-none-any.whl
| Download URL | discord_logging_handler-0.3.1-py3-none-any.whl |
|---|---|
| Size | 4.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ee3efa1653dcabc77ca2bc102155e03966c6b8a3eb7f4ce70876a52f1b780f3c
|
|
BLAKE2b-256 checksum How to use checksums |
4383ae0ef4e977e205452b7b726621218671ded0ad6ff6bfbc0c4197a53b906e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.6
|