Skip to main content

====================== Django Log to Telegram

This is a simple logger that sends 500 exceptions to a Telegram bot of your choice.

Quick start

Install django-log-to-telegram:

.. code:: bash

pip install django_log_to_telegram
  1. register a bot on Telegram (with BotFather <https://core.telegram.org/bots#6-botfather>_), start a chat with it and put the Api token in settings.py:

.. code:: python

LOG_TO_TELEGRAM_BOT_TOKEN = '12345678:replace-me-with-real-token'

Different errors will be fired if the BOT_TOKEN is not active or if there is no chat active with it.

  1. add the 'django_log_to_telegram' to your INSTALLED_APPS setting:

.. code:: python

INSTALLED_APPS = [
    ...
    'django_log_to_telegram',
    ...
]
  1. add the django_log_to_telegram.log.AdminTelegramHandler to your app's logging configuration, for example:

.. code:: python

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'filters': {
        'require_debug_false': {
            '()': 'django.utils.log.RequireDebugFalse'
        }
    },
    'handlers': {
        'telegram_log': {
            'level': 'ERROR',
            'filters': ['require_debug_false'],
            'class': 'django_log_to_telegram.log.AdminTelegramHandler',
            'bot_token': LOG_TO_TELEGRAM_BOT_TOKEN,
        }
    },
    'loggers': {
        'django.request': {
            'handlers': ['telegram_log'],
            'level': 'ERROR',
            'propagate': True,
        },
    },
}

if you want to test this logger in a debug environment, just remove the filters': ['require_debug_false'], line in the 'handlers' dictionary.

  1. Run python manage.py migrate to create the django_log_to_telegram models.

If everything went well, you bot will then begin sending messages on 500 exceptions.

There is a very basic test app provided in the folder test_app. It is configured to send errors to telegram even with DEBUG active, so that it can be useful with just a

.. code:: python

./manage.py runserver

It does not provide any database configuration, and most of Django basic settings are stripped out, so any use of it outside the very basic testing of the django_log_to_telegram mechanism is deprecated to say the least.

Release files for django-log-to-telegram 2023.12.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-log-to-telegram 2023.12.18
File Size Uploaded
django_log_to_telegram-2023.12.18.tar.gz 20.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-log-to-telegram 2023.12.18
File Interpreter ABI Platform
django_log_to_telegram-2023.12.18-py3-none-any.whl Python 3 none any Details

Total release size: 39.5 kB

Release files / django_log_to_telegram-2023.12.18.tar.gz

Download URL django_log_to_telegram-2023.12.18.tar.gz
Size 20.5 kB
Tags Source
SHA-256 checksum
How to use checksums
522cd9d7140ff328cf31e2c06d80f47bd7410748893b7a5ad0787797ccf082e6
BLAKE2b-256 checksum
How to use checksums
3c32c11a28b78b9714010763dca0a4a789a42d61a1dcee48ab25d6f4b886daf3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / django_log_to_telegram-2023.12.18-py3-none-any.whl

Download URL django_log_to_telegram-2023.12.18-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7f951b85713f1f4936620c6958dba722d98609363d5260b923251d4d3e173e2c
BLAKE2b-256 checksum
How to use checksums
399431898638863cc1d077637ce7c28d0ea193dd68af63219e8200a0995b6455
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page