python-telegram-bot / ptbcontrib

Community-based extensions for the python-telegram-bot library.
https://python-telegram-bot.org
GNU General Public License v3.0
104 stars 41 forks source link

Log forwarder #113

Closed Lur1an closed 2 months ago

Lur1an commented 3 months ago

Logging handler for python-telegram-bot

Extension to forward application logs to specific Telegram chats through a logging.Handler class.

Usage

Initialize the log forwarder in your on_startup method:

async def on_startup(app: Application):
    error_forwarder = LogForwarder(
        app.bot, [CHAT_ID], log_levels=["ERROR", "WARNING"]
    )
    # Add handler to the root logger to apply to all other loggers
    logging.getLogger().addHandler(error_forwarder)
Bibo-Joshi commented 2 months ago

Thank you very much for the contribution :)

Bibo-Joshi commented 2 months ago

Mh, unfortunately there seems to be a problem on python 3.8: https://github.com/python-telegram-bot/ptbcontrib/actions/runs/10455010888/job/28948996383. Not sure why it didn't show in the tests here … Could you kindly open a follow-up PR?