mirror of
https://github.com/otter18/tg_logger.git
synced 2025-08-10 21:41:59 +02:00
Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ce7560ef22 | ||
|
91e2d68f86 | ||
|
66d5c20105 | ||
|
919539e7f7 | ||
|
8c5038a878 | ||
|
122cda5252 | ||
|
42f8ed3c5c | ||
|
a493cca053 | ||
|
de3526bb87 | ||
|
f6066abc43 | ||
|
159c18826d | ||
|
74fd1c4fa2 | ||
|
09977fbac0 | ||
|
882fdc4ad0 | ||
|
edbbdac6e4 | ||
|
e6833597a6 | ||
|
63d00bad8d | ||
|
698b79eb54 | ||
|
1d851a1a59 |
56
README.md
56
README.md
@@ -1,32 +1,39 @@
|
||||
#  Telegram logger [](https://github.com/otter18/tg_logger/stargazers)
|
||||
[](https://pypi.org/project/tg-logger/)
|
||||
[](https://pypi.org/project/tg-logger/)
|
||||
[](https://pypi.org/project/tg-logger/)
|
||||
[](https://pepy.tech/project/tg-logger)
|
||||
[](https://github.com/otter18/tg_logger/blob/main/LICENSE)
|
||||
[](https://tg-logger.readthedocs.io/en/latest/?badge=latest)
|
||||
|
||||
<!-- [](https://pypi.org/project/tg-logger/) -->
|
||||
|
||||
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)]
|
||||
|
||||

|
||||
|
||||
## 🗂 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
|
||||

|
||||
|
||||
## Examples
|
||||
## 📖 Examples
|
||||
### Simple logging
|
||||
```python
|
||||
import logging
|
||||
@@ -50,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
|
||||
@@ -73,6 +81,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
|
||||
@@ -95,9 +127,11 @@ with open(file_name, 'w') as example_file:
|
||||
tg_files_logger.send(file_name, "Test file")
|
||||
```
|
||||
|
||||
## FQA
|
||||
## 🔎 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))
|
||||
|
||||
|
@@ -12,7 +12,7 @@
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
sys.path.insert(0, os.path.abspath('../tg_logger'))
|
||||
sys.path.insert(0, os.path.abspath('...'))
|
||||
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
@@ -22,7 +22,7 @@ copyright = '2021, ChernV (otter18)'
|
||||
author = 'ChernV (otter18)'
|
||||
|
||||
# The full version, including alpha/beta/rc tags
|
||||
release = '3.0'
|
||||
release = 'v3.1'
|
||||
|
||||
|
||||
# -- General configuration ---------------------------------------------------
|
||||
@@ -58,4 +58,4 @@ html_theme = 'sphinx_rtd_theme'
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
# relative to this directory. They are copied after the builtin static files,
|
||||
# so a file named "default.css" will overwrite the builtin "default.css".
|
||||
html_static_path = ['_static']
|
||||
html_static_path = ['_static']
|
||||
|
@@ -9,5 +9,6 @@ To create bot use official `BotFather <https://t.me/BotFather>`_ bot (descibed `
|
||||
How to get **token** and **user_id**?
|
||||
*************************************
|
||||
|
||||
- Use `@tg_logger_demo_bot <https://t.me/tg_logger_demo_bot>`_ with command :code:`/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>`_)
|
||||
- To get **user_id** use special bots (e.g. `@userinfobot <https://t.me/userinfobot>`_, `@JsonDumpBot <https://t.me/JsonDumpBot>`_)
|
||||
|
@@ -6,6 +6,8 @@
|
||||
Welcome to tg-logger's documentation!
|
||||
=====================================
|
||||
|
||||
Demo is available `@tg_logger_demo_bot <https://t.me/tg_logger_demo_bot>`_
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 2
|
||||
:caption: Contents:
|
||||
@@ -19,7 +21,7 @@ Links
|
||||
=====
|
||||
- Github: https://github.com/otter18/tg_logger
|
||||
- Pypi: https://pypi.org/project/tg-logger
|
||||
|
||||
- Demo bot: https://t.me/tg_logger_demo_bot
|
||||
|
||||
..
|
||||
Indices and tables
|
||||
|
@@ -1,7 +1,7 @@
|
||||
Module description
|
||||
===================
|
||||
|
||||
.. automodule:: tg_logger.__init__
|
||||
.. automodule:: tg_logger
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
BIN
img/intro.jpeg
Normal file
BIN
img/intro.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 68 KiB |
BIN
img/intro2.jpeg
Normal file
BIN
img/intro2.jpeg
Normal file
Binary file not shown.
After Width: | Height: | Size: 78 KiB |
2
setup.py
2
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",
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user