Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

tglogger is a logger handler and formatter for Telegram bots.

Project description

tglogger

PyPI - Version PyPI - Status PyPI - License PyPI - Python PyPI - Django Downloads - Month

tglogger contains utilities to build and redirect logs to Telegram chat via a bot.

  • It has a formatter for beautiful log messages in Telegram.
  • It tends to tag common logs so that you can easily filter out related log messages.
  • You can send logs to individuals, channels or groups.
  • It works with Django (See badges for supported versions).
Build Coverage
master Linux - Master Coverage - Master
development Linux - Development Coverage - Development

Installing

Install via pip:

pip install tglogger

Example

tglogger contains a formatter which formats log records for Telegram chats and a handler which sends log records to a Telegram chat.

Assuming you have a logger instance:

logger = logging.getLogger(__name__)

You need to have an instance of TelegramHandler and TelegramFormatter.

from tglogger import TelegramHandler, TelegramFormatter

handler = TelegramHandler(bot_token="foo", receiver="bar")
# you can also set TELEGRAM_BOT_TOKEN and TELEGRAM_RECEIVER
# environment variables so as not to pass these on initialization

formatter = TelegramFormatter() # initialize formatter
handler.setFormatter(formatter)  # inject formatter into handler

logger.addHandler(handler)  # inject handler into logger

And now your log records that has level above ERROR will be sent to the chat you have defined with receiver by the bot that you have defined by bot_token.

logger.error("foo")  # you will receive a message by your bot

Documentation

Documentation has more information about how to use tglogger. Refer to the documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for tglogger, version 0.1.1a3
Filename, size File type Python version Upload date Hashes
Filename, size tglogger-0.1.1a3-py3-none-any.whl (6.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size tglogger-0.1.1a3.tar.gz (5.3 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page