Skip to main content

Python log error or exception callback

Project description

err-callback-py

Python log error or exception callback

install

pip install errcallback

Usage

logging callback

import logging

from errcallback import registry_err_callback

logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)


def callback_func(record):
    logger.info("callback func lineno: %s message: %s",
                record.lineno, record.message)


registry_err_callback(logger_func=callback_func, log_level=logging.ERROR)

logger.info("info test")
logger.error("error test")


# output
INFO:__main__:info test
ERROR:__main__:error test
INFO:__main__:callback func lineno: 17 message: error test

exception callback

import logging

from errcallback import registry_err_callback


def callback_func(exc_type, exc_value, exc_traceback):
    logging.error("callback_func>>>>>>>>>>>>>>", exc_info=(
        exc_type, exc_value, exc_traceback))


registry_err_callback(exception_func=callback_func)

1 / 0


# output
ERROR:root:callback_func>>>>>>>>>>>>>>
Traceback (most recent call last):
  File "examples/exception_demo.py", line 13, in <module>
    1 / 0
ZeroDivisionError: division by zero

callback message to DingTalk, Email, Prometheus

...
from errcallback import registry_err_callback


def callback_func(exc_type, exc_value, exc_traceback):
    # todo send to DingTalk, Email, Prometheus


registry_err_callback(exception_func=callback_func)
...

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

errcallback-0.0.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

errcallback-0.0.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file errcallback-0.0.1.tar.gz.

File metadata

  • Download URL: errcallback-0.0.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for errcallback-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c720420007e694ece4e07c71b54769eee79521eac8bb60e51950a2588785dcaf
MD5 913cdd58e333d4d6d2a5a0c54e0dd351
BLAKE2b-256 bc1620d2412e2d1810f4b774db38b8d053d9cb166deb8606f585b9aae12214c7

See more details on using hashes here.

File details

Details for the file errcallback-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: errcallback-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5

File hashes

Hashes for errcallback-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 63ad023f6f81e323d0bb7f79f0e08e4b1d9d282e9886e1269a163312a0637b9b
MD5 8c937b61e104fd56396c7483954e6263
BLAKE2b-256 267a4abbb148721fd022a2bc44bbd5229e36827d659f3e054af91aee020472f6

See more details on using hashes here.

Supported by

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