A tool to bridge python logging and user files to telegram bot
Project description
Telegram logger
Bridging python logging and files to tg bot
Documentation is available at Read the Docs
Demo is available @tg_logger_demo_bot, [repo]
🗂 Table of Contents
🚀 Installation & Usage
- Available by
pip install tg-logger
- Use with
import tg_logger
📱 Screenshot
📖 Examples
Simple logging
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
tg_logger.setup(logger, token=token, users=users)
# Test
logger.info("Hello from tg_logger by otter18")
Flask logging
from flask import Flask
import logging
import tg_logger
# Telegram data
token = "1234567890:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
users = [1111111111]
# Flask app setup
app = Flask(__name__)
app.logger.setLevel(logging.ERROR) # flask logger
tg_logger.setup(app.logger, token=token, users=users) # bridge setup
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run()
Setting extra parameters to handler
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
import tg_logger
# Telegram data
token = "1234567890:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
users = [1111111111]
# TgFileLogger example
tg_files_logger = tg_logger.TgFileLogger(
token=token, # tg bot token
users=users, # list of user_id
timeout=10 # 10 seconds by default
)
file_name = "test.txt"
with open(file_name, 'w') as example_file:
example_file.write("Hello from tg_logger by otter18")
tg_files_logger.send(file_name, "Test file")
🔎 FQA
How to create a telegram bot?
How to get token and user_id?
- Use @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, @JsonDumpBot)
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
tg_logger-3.3.tar.gz
(4.5 kB
view details)
Built Distribution
File details
Details for the file tg_logger-3.3.tar.gz
.
File metadata
- Download URL: tg_logger-3.3.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42c576d442229b537de276e77d9613fea7e15fbc3a5212574d9096c5fb26a6d5 |
|
MD5 | 9119d1a73ee1053415e3af324fb66055 |
|
BLAKE2b-256 | c20bea1fa72db9fb4c513d492aede24b360fa461c071af57df1912a4d6f5d967 |
File details
Details for the file tg_logger-3.3-py3-none-any.whl
.
File metadata
- Download URL: tg_logger-3.3-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbdd4330b71fa16a67644bac24969dfc6ed643f1e748c80b7b0706ecb32122ad |
|
MD5 | d171f23098b4faa2df382db4d147d545 |
|
BLAKE2b-256 | d6236ae5e38dc5d78e5319a510207f9531c98733d23b198725fc36f6c6319e77 |