Skip to main content

Provides an interface for using a discord webhook as a logger.

Project description

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

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

async def main():
    basicConfig(level=ERROR, handlers=[StreamHandler(), DiscordWebhookHandler("url", run_async=True, 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

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

dislog-2.2.1.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

dislog-2.2.1-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

Details for the file dislog-2.2.1.tar.gz.

File metadata

  • Download URL: dislog-2.2.1.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for dislog-2.2.1.tar.gz
Algorithm Hash digest
SHA256 0ac0c114e12617b68ca7dd594aed2b47d64e78e1d21684e369381036bfe38d6c
MD5 53e57a9c206b1c65a05f0fc871ac8daf
BLAKE2b-256 36222d67787dbefe0de52cf708bd868730efb2221637c4636ccdabedc16c9d8f

See more details on using hashes here.

Provenance

File details

Details for the file dislog-2.2.1-py3-none-any.whl.

File metadata

  • Download URL: dislog-2.2.1-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for dislog-2.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0940e7dee9a6c8e26767f805165f6a0de1a27f6ddf9bdd641da9e65fe1e88d75
MD5 e0cd7991486085505af6df55b69a7e8f
BLAKE2b-256 5ae39840a7e8d40e19a986d821037ee74b0364852dab5acb2763910d338fdd9d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page