Welcome to tg-logger’s documentation!
Demo is available @tg_logger_demo_bot
Introduction
Tg-logger is took for bridging python logging and files to tg bot
Installation & Usage
pip install tg-logger
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 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()
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")
Module description
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)
License
MIT License
Copyright (c) 2021 ChernV
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Links
Demo bot: https://t.me/tg_logger_demo_bot