mirror of
https://github.com/otter18/tg_logger.git
synced 2025-06-18 21:47:37 +02:00
version 3.2-beta
This commit is contained in:
56
README.md
56
README.md
@ -1,38 +1,33 @@
|
|||||||
#  Telegram logger [](https://github.com/otter18/tg_logger/stargazers)
|
#  Telegram logger [](https://github.com/otter18/tg_logger/stargazers)
|
||||||
[](https://pypi.org/project/tg-logger/)
|
[](https://pypi.org/project/tg-logger/)
|
||||||
[](https://pepy.tech/project/tg-logger)
|
[](https://pypi.org/project/tg-logger/)
|
||||||
[](https://github.com/otter18/tg_logger/blob/main/LICENSE)
|
[](https://github.com/otter18/tg_logger/blob/main/LICENSE)
|
||||||
[](https://tg-logger.readthedocs.io/en/latest/?badge=latest)
|
[](https://tg-logger.readthedocs.io/en/latest/?badge=latest)
|
||||||
|
|
||||||
<!-- [](https://pypi.org/project/tg-logger/) -->
|
|
||||||
|
|
||||||
Bridging python logging and files to tg bot
|
Bridging python logging and files to tg bot
|
||||||
|
|
||||||
Documentation is available at [Read the Docs](https://tg-logger.readthedocs.io/)
|
Documentation is available at [Read the Docs](https://tg-logger.readthedocs.io/)
|
||||||
|
|
||||||
Demo is available [@tg_logger_demo_bot](https://t.me/tg_logger_demo_bot), [[repo](https://github.com/otter18/tg-logger-demo-bot)]
|
## Table of Contents
|
||||||
|
- [Installation & Usage](#installation--usage)
|
||||||

|
- [Screenshot](#screenshot)
|
||||||
|
- [Examples](#examples)
|
||||||
## 🗂 Table of Contents
|
|
||||||
- [Installation & Usage](#-installation--usage)
|
|
||||||
- [Screenshot](#-screenshot)
|
|
||||||
- [Examples](#-examples)
|
|
||||||
* [Simple logging](#simple-logging)
|
* [Simple logging](#simple-logging)
|
||||||
* [Flask logging](#flask-logging)
|
* [Flask logging](#flask-logging)
|
||||||
|
* [Setting extra parameters to handler](#setting-extra-parameters-to-handler)
|
||||||
* [TgFileLogger example](#tgfilelogger-example)
|
* [TgFileLogger example](#tgfilelogger-example)
|
||||||
- [FQA](#-fqa)
|
- [FQA](#fqa)
|
||||||
* [How to create a telegram bot?](#how-to-create-a-telegram-bot)
|
* [How to create a telegram bot?](#how-to-create-a-telegram-bot)
|
||||||
* [How to get **token** and **user_id**?](#how-to-get-token-and-user_id)
|
* [How to get **token** and **user_id**?](#how-to-get-token-and-user_id)
|
||||||
|
|
||||||
## 🚀 Installation & Usage
|
## Installation & Usage
|
||||||
- Available by `pip install tg-logger`
|
- Available by `pip install tg-logger`
|
||||||
- Use with `import tg_logger`
|
- Use with `import tg_logger`
|
||||||
|
|
||||||
## 📱 Screenshot
|
## Screenshot
|
||||||

|

|
||||||
|
|
||||||
## 📖 Examples
|
## Examples
|
||||||
### Simple logging
|
### Simple logging
|
||||||
```python
|
```python
|
||||||
import logging
|
import logging
|
||||||
@ -56,7 +51,6 @@ logger.info("Hello from tg_logger by otter18")
|
|||||||
### Flask logging
|
### Flask logging
|
||||||
```python
|
```python
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
import logging
|
|
||||||
import tg_logger
|
import tg_logger
|
||||||
|
|
||||||
# Telegram data
|
# Telegram data
|
||||||
@ -80,6 +74,30 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Setting extra parameters to handler
|
||||||
|
|
||||||
|
```python
|
||||||
|
import logging
|
||||||
|
import tg_logger
|
||||||
|
|
||||||
|
# Telegram data
|
||||||
|
token = "1234567890:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
|
||||||
|
users = [1111111111]
|
||||||
|
|
||||||
|
# Base logger
|
||||||
|
logger = logging.getLogger('foo')
|
||||||
|
logger.setLevel(logging.INFO)
|
||||||
|
|
||||||
|
# Logging bridge setup
|
||||||
|
handler = tg_logger.setup(logger, token=token, users=users)
|
||||||
|
|
||||||
|
# Setting extra params
|
||||||
|
handler.setLevel(logging.DEBUG)
|
||||||
|
|
||||||
|
# Test
|
||||||
|
logger.info("Hello from tg_logger by otter18")
|
||||||
|
```
|
||||||
|
|
||||||
### TgFileLogger example
|
### TgFileLogger example
|
||||||
```python
|
```python
|
||||||
import tg_logger
|
import tg_logger
|
||||||
@ -102,11 +120,9 @@ with open(file_name, 'w') as example_file:
|
|||||||
tg_files_logger.send(file_name, "Test file")
|
tg_files_logger.send(file_name, "Test file")
|
||||||
```
|
```
|
||||||
|
|
||||||
## 🔎 FQA
|
## FQA
|
||||||
### How to create a telegram bot?
|
### How to create a telegram bot?
|
||||||
- To create bot use official [BotFather](https://t.me/BotFather) bot (descibed [here](https://core.telegram.org/bots#6-botfather))
|
- To create bot use official [BotFather](https://t.me/BotFather) bot (descibed [here](https://core.telegram.org/bots#6-botfather))
|
||||||
### How to get **token** and **user_id**?
|
### How to get **token** and **user_id**?
|
||||||
- Use [@tg_logger_demo_bot](https://t.me/tg_logger_demo_bot) with command `/id`
|
|
||||||
- Bot's **token** is shown after new bot is made
|
- Bot's **token** is shown after new bot is made
|
||||||
- To get **user_id** use special bots (e.g. [@userinfobot](https://t.me/userinfobot), [@JsonDumpBot](https://t.me/JsonDumpBot))
|
- To get **user_id** use special bots (e.g. [@userinfobot](https://t.me/userinfobot), [@JsonDumpBot](https://t.me/JsonDumpBot))
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="tg_logger",
|
name="tg_logger",
|
||||||
version="3.1",
|
version="3.2",
|
||||||
description="A tool to bridge python logging and user files to telegram bot",
|
description="A tool to bridge python logging and user files to telegram bot",
|
||||||
long_description=open("README.md").read(),
|
long_description=open("README.md").read(),
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
|
@ -21,7 +21,7 @@ def setup(base_logger: logging.Logger = logging.getLogger(),
|
|||||||
:param timeout: seconds for retrying to send log if error occupied
|
:param timeout: seconds for retrying to send log if error occupied
|
||||||
:param tg_format: logging format for tg messages (html parse mode)
|
:param tg_format: logging format for tg messages (html parse mode)
|
||||||
|
|
||||||
:return: None
|
:return: logging.StreamHandler
|
||||||
"""
|
"""
|
||||||
# Logging format
|
# Logging format
|
||||||
formatter = logging.Formatter(tg_format)
|
formatter = logging.Formatter(tg_format)
|
||||||
@ -34,3 +34,5 @@ def setup(base_logger: logging.Logger = logging.getLogger(),
|
|||||||
)
|
)
|
||||||
tg_handler.setFormatter(formatter)
|
tg_handler.setFormatter(formatter)
|
||||||
base_logger.addHandler(tg_handler)
|
base_logger.addHandler(tg_handler)
|
||||||
|
|
||||||
|
return tg_handler
|
||||||
|
Reference in New Issue
Block a user