Provides an interface for using a discord webhook as a logger.
Project description
dislog
Previously discord-webhook-logger
Provides an interface for using a Discord webhook as a logger.
Designed to abstract away webhook-specific details, such as the JSON format, and provide a simple interface for logging messages.
Install
Simple as:
pip install dislog[discordpy]
You can use extras to define which implementation of discord.py
you want to use.
discordpy
: `discord.py
Example
Using dislog
in your projects is dead simple. It behaves like any other logging.Handler
.
For performance reasons, it even fires off a new thread for each log message, so you don't have to worry about blocking your main thread with costly HTTP requests.
from dislog import DiscordWebhookHandler
from logging import *
basicConfig(level=ERROR, handlers=[StreamHandler(), DiscordWebhookHandler("url", text_send_on_error="<@440468612365680650>")])
error("hi")
It also works with asynchronous code, simply pass the run_async
keyword argument. This is optional and makes it use the event loop instead of a thread pool.
from dislog import DiscordWebhookHandler
from logging import *
from asyncio import run, sleep, get_running_loop
async def main():
basicConfig(level=ERROR, handlers=[StreamHandler(), DiscordWebhookHandler("url", event_loop=get_running_loop(), text_send_on_error="<@440468612365680650>")])
error("hi")
await sleep(1) # Give it some time to run!
run(main())
Contributing
Setup
git clone https://github.com/regulad/dislog
cd dislog
pip install -e .
pre-commit install
Testing
tox
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
Built Distribution
File details
Details for the file dislog-3.0.0.tar.gz
.
File metadata
- Download URL: dislog-3.0.0.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 586d17e2d53bdb5c571fce3379e688a9c0038019f0144f43dba234aa08b89725 |
|
MD5 | 9328656ed41f840325b07797c8d2caed |
|
BLAKE2b-256 | a777bdb70251ef68eae5895e42992cbf966c11299098016f98ce5c4810028008 |
File details
Details for the file dislog-3.0.0-py3-none-any.whl
.
File metadata
- Download URL: dislog-3.0.0-py3-none-any.whl
- Upload date:
- Size: 18.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 763ca74e98e174bf317edd8bd25494f36cadce4b2e4a13a44db075610b8354c3 |
|
MD5 | ed5edf2e63de259c48271934b7254ea3 |
|
BLAKE2b-256 | 40ddd6c73d718c291ebe1de51eaeb1ee58e30432eac58e027c5a6a7f5ba5aa9c |