Skip to main content

Yet another telegram logger

Project description

Yet Another Telegram Logger

A python library to log messages and exceptions to your Telegram bot.

Setup

1. Create a bot

First, create a new bot. It's basically sending some messages to @BotFather.

2. Create a config file (.yatlogger.json)

Next, create a file named .yatlogger.json and place it in the same directory as your code or in a one of the parent directories. The file must look like this:

{
    "token": "<your api key>"
}

Replace <your api key> with the API key you got from the BotFather.

3. Register chats

Your bot must know to which chats it should send the logs. So the next step is to register receiving chats.

Run python -m yatlogger to start the register service. As long as this service is running, you can register new chats.

To register a chat, start a chat with your bot and enter the 6 digit pin you see on the logging machine.

register a new chat

When you are done, you can simply interrupt the register service with Ctrl + C

Usage

yatlogger registers itself as a handler for the built-in logging module. Here is an example:

import logging
import yatlogger

logger = yatlogger.register()
logger.setLevel(logging.INFO)

logger.info("Read this on your phone!")

raise ValueError("This unhandled exception will be sent to Telegram, too!")

And the resulting chat messages:

log messages on telegram

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

yatlogger-0.1.3.tar.gz (4.7 kB view hashes)

Uploaded Source

Built Distribution

yatlogger-0.1.3-py3-none-any.whl (5.3 kB view hashes)

Uploaded Python 3

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