1
0
Fork 0
mirror of synced 2026-12-06 18:22:25 +00:00
No description
Find a file
2023-03-08 21:06:06 -05:00
.github v2.2.1 2023-02-18 16:12:53 -05:00
src/dislog v3 - stability 2023-03-08 21:06:06 -05:00
tests v3 - stability 2023-03-08 21:06:06 -05:00
.gitattributes tagged before the setup.cfg change 2022-01-03 18:32:15 -05:00
.gitignore Initial commit 2022-01-02 16:44:03 -05:00
.pre-commit-config.yaml v2.2.0 2023-02-18 15:46:58 -05:00
LICENSE Initial commit 2022-01-02 16:44:03 -05:00
mypy.ini v2.2.0 2023-02-18 15:46:58 -05:00
pyproject.toml v3 - stability 2023-03-08 21:06:06 -05:00
README.md v3 - stability 2023-03-08 21:06:06 -05:00
Screenshot 2023-02-18 154119.png v2.2.0 2023-02-18 15:46:58 -05:00
Screenshot 2023-02-18 154139.png v2.2.0 2023-02-18 15:46:58 -05:00
setup.cfg v3 - stability 2023-03-08 21:06:06 -05:00
setup.py Typing 2023-01-30 08:00:17 -05:00
tox.ini v3 - stability 2023-03-08 21:06:06 -05:00

dislog

wakatime GitHub Workflow Status pre-commit.ci status PyPI PyPI - Python Version

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")

Demo

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())

Async Demo

Contributing

Setup

git clone https://github.com/regulad/dislog
cd dislog
pip install -e .
pre-commit install

Testing

tox