From 91e2d68f86b113d6742e7f63af86872d6027f5be Mon Sep 17 00:00:00 2001 From: ChernV Date: Sat, 6 Nov 2021 18:01:10 +0300 Subject: [PATCH 1/3] version 3.2-beta --- README.md | 58 +++++++++++++++++++++++++++---------------- setup.py | 2 +- tg_logger/__init__.py | 4 ++- 3 files changed, 41 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 93d2a3d..f6fb8ee 100644 --- a/README.md +++ b/README.md @@ -1,38 +1,33 @@ # ![tg_logo](https://raw.githubusercontent.com/otter18/tg_logger/master/img/telegram-icon.png) Telegram logger [![GitHub Repo stars](https://img.shields.io/github/stars/otter18/tg_logger?style=social)](https://github.com/otter18/tg_logger/stargazers) -[![Pypi version](https://img.shields.io/pypi/v/tg-logger.svg)](https://pypi.org/project/tg-logger/) -[![Downloads](https://static.pepy.tech/personalized-badge/tg-logger?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads)](https://pepy.tech/project/tg-logger) +[![](https://img.shields.io/pypi/v/tg-logger.svg)](https://pypi.org/project/tg-logger/) +[![](https://img.shields.io/pypi/pyversions/tg-logger.svg)](https://pypi.org/project/tg-logger/) [![GitHub](https://img.shields.io/github/license/otter18/tg_logger)](https://github.com/otter18/tg_logger/blob/main/LICENSE) [![Documentation Status](https://readthedocs.org/projects/tg-logger/badge/?version=latest)](https://tg-logger.readthedocs.io/en/latest/?badge=latest) - - Bridging python logging and files to tg bot 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)] - -![intro_img](https://raw.githubusercontent.com/otter18/tg_logger/main/img/intro.jpeg) - -## 🗂 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) * [Flask logging](#flask-logging) + * [Setting extra parameters to handler](#setting-extra-parameters-to-handler) * [TgFileLogger example](#tgfilelogger-example) -- [FQA](#-fqa) +- [FQA](#fqa) * [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) -## 🚀 Installation & Usage +## Installation & Usage - Available by `pip install tg-logger` - Use with `import tg_logger` -## 📱 Screenshot +## Screenshot ![example_scr](https://raw.githubusercontent.com/otter18/tg_logger/master/img/example_scr.png) -## 📖 Examples +## Examples ### Simple logging ```python import logging @@ -56,7 +51,6 @@ logger.info("Hello from tg_logger by otter18") ### Flask logging ```python from flask import Flask -import logging import tg_logger # 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 ```python import tg_logger @@ -102,11 +120,9 @@ with open(file_name, 'w') as example_file: tg_files_logger.send(file_name, "Test file") ``` -## 🔎 FQA -### How to create a telegram bot? +## FQA +### 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)) ### 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 - To get **user_id** use special bots (e.g. [@userinfobot](https://t.me/userinfobot), [@JsonDumpBot](https://t.me/JsonDumpBot)) - diff --git a/setup.py b/setup.py index a18df80..0f8a056 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="tg_logger", - version="3.1", + version="3.2", description="A tool to bridge python logging and user files to telegram bot", long_description=open("README.md").read(), long_description_content_type="text/markdown", diff --git a/tg_logger/__init__.py b/tg_logger/__init__.py index faf665c..b6cf581 100644 --- a/tg_logger/__init__.py +++ b/tg_logger/__init__.py @@ -21,7 +21,7 @@ def setup(base_logger: logging.Logger = logging.getLogger(), :param timeout: seconds for retrying to send log if error occupied :param tg_format: logging format for tg messages (html parse mode) - :return: None + :return: logging.StreamHandler """ # Logging format formatter = logging.Formatter(tg_format) @@ -34,3 +34,5 @@ def setup(base_logger: logging.Logger = logging.getLogger(), ) tg_handler.setFormatter(formatter) base_logger.addHandler(tg_handler) + + return tg_handler From ce7560ef222d94b55866b2cc66f3d57a8f0a9709 Mon Sep 17 00:00:00 2001 From: ChernV Date: Sat, 6 Nov 2021 18:04:41 +0300 Subject: [PATCH 2/3] README.md fix --- README.md | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f6fb8ee..ed83174 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,39 @@ # ![tg_logo](https://raw.githubusercontent.com/otter18/tg_logger/master/img/telegram-icon.png) Telegram logger [![GitHub Repo stars](https://img.shields.io/github/stars/otter18/tg_logger?style=social)](https://github.com/otter18/tg_logger/stargazers) -[![](https://img.shields.io/pypi/v/tg-logger.svg)](https://pypi.org/project/tg-logger/) -[![](https://img.shields.io/pypi/pyversions/tg-logger.svg)](https://pypi.org/project/tg-logger/) +[![Pypi version](https://img.shields.io/pypi/v/tg-logger.svg)](https://pypi.org/project/tg-logger/) +[![Downloads](https://static.pepy.tech/personalized-badge/tg-logger?period=total&units=international_system&left_color=grey&right_color=orange&left_text=Downloads)](https://pepy.tech/project/tg-logger) [![GitHub](https://img.shields.io/github/license/otter18/tg_logger)](https://github.com/otter18/tg_logger/blob/main/LICENSE) [![Documentation Status](https://readthedocs.org/projects/tg-logger/badge/?version=latest)](https://tg-logger.readthedocs.io/en/latest/?badge=latest) + + Bridging python logging and files to tg bot Documentation is available at [Read the Docs](https://tg-logger.readthedocs.io/) -## Table of Contents -- [Installation & Usage](#installation--usage) -- [Screenshot](#screenshot) -- [Examples](#examples) +Demo is available [@tg_logger_demo_bot](https://t.me/tg_logger_demo_bot), [[repo](https://github.com/otter18/tg-logger-demo-bot)] + +![intro_img](https://raw.githubusercontent.com/otter18/tg_logger/main/img/intro.jpeg) + +## 🗂 Table of Contents +- [Installation & Usage](#-installation--usage) +- [Screenshot](#-screenshot) +- [Examples](#-examples) * [Simple logging](#simple-logging) * [Flask logging](#flask-logging) * [Setting extra parameters to handler](#setting-extra-parameters-to-handler) * [TgFileLogger example](#tgfilelogger-example) -- [FQA](#fqa) +- [FQA](#-fqa) * [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) -## Installation & Usage +## 🚀 Installation & Usage - Available by `pip install tg-logger` - Use with `import tg_logger` -## Screenshot +## 📱 Screenshot ![example_scr](https://raw.githubusercontent.com/otter18/tg_logger/master/img/example_scr.png) -## Examples +## 📖 Examples ### Simple logging ```python import logging @@ -51,6 +57,7 @@ logger.info("Hello from tg_logger by otter18") ### Flask logging ```python from flask import Flask +import logging import tg_logger # Telegram data @@ -120,9 +127,11 @@ with open(file_name, 'w') as example_file: tg_files_logger.send(file_name, "Test file") ``` -## FQA -### How to create a telegram bot? +## 🔎 FQA +### 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)) ### 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 - To get **user_id** use special bots (e.g. [@userinfobot](https://t.me/userinfobot), [@JsonDumpBot](https://t.me/JsonDumpBot)) + From 1ebbc9e3ac125574e144529a40516007cc5e902f Mon Sep 17 00:00:00 2001 From: ChernV Date: Fri, 31 Dec 2021 10:31:39 +0300 Subject: [PATCH 3/3] version 3.3 --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 0f8a056..9f0b49a 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup( name="tg_logger", - version="3.2", + version="3.3", description="A tool to bridge python logging and user files to telegram bot", long_description=open("README.md").read(), long_description_content_type="text/markdown", @@ -11,7 +11,7 @@ setup( url="https://github.com/otter18/tg_logger", packages=find_packages(), install_requires=[ - "pyTelegramBotAPI==3.7.6", + "pyTelegramBotAPI>=3.7.6", ], classifiers=[ "Programming Language :: Python :: 3",