Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cyd3r/yatlogger
Yet Another Telegram Logger
https://github.com/cyd3r/yatlogger
logging python python-3 telegram telegram-bot telegram-logger
Last synced: 19 days ago
JSON representation
Yet Another Telegram Logger
- Host: GitHub
- URL: https://github.com/cyd3r/yatlogger
- Owner: cyd3r
- Created: 2021-06-07T09:52:41.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-01-19T09:20:47.000Z (almost 3 years ago)
- Last Synced: 2024-10-07T19:12:13.788Z (29 days ago)
- Topics: logging, python, python-3, telegram, telegram-bot, telegram-logger
- Language: Python
- Homepage:
- Size: 124 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Yet Another Telegram Logger
A python library to log messages and exceptions to your [Telegram bot](https://core.telegram.org/bots). This package has zero dependencies to external libraries and only relies on Python's built-in features.
## Usage
yatlogger registers itself as a handler for the built-in [logging](https://docs.python.org/3/library/logging.html) module. Here is an example:
``` python
import logging
import yatloggerlogger = 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](https://raw.githubusercontent.com/cyd3r/yatlogger/main/docs/logs.jpg)
## Setup
### 1. Create a bot
First, [create a new bot](https://core.telegram.org/bots#creating-a-new-bot). It's basically sending some messages to [@BotFather](https://t.me/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 one of the parent directories. The file must look like this:
``` json
{
"token": ""
}
```Replace `` 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 in the console output.
![register a new chat](https://raw.githubusercontent.com/cyd3r/yatlogger/main/docs/register_chat.jpg)
When you are done, stop the register service with Ctrl + C