Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log forwarder #113

Merged
merged 8 commits into from
Aug 19, 2024
Merged

Log forwarder #113

merged 8 commits into from
Aug 19, 2024

Conversation

Lur1an
Copy link
Contributor

@Lur1an Lur1an commented Aug 2, 2024

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)

@Lur1an Lur1an marked this pull request as ready for review August 2, 2024 20:33
Copy link
Member

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. Thanks for your PR! I left a few smaller comments below. Additionally, Please also have a look at the failing pre-commit tests.

ptbcontrib/log_forwarder/README.md Show resolved Hide resolved
ptbcontrib/log_forwarder/log_forwarder.py Outdated Show resolved Hide resolved
ptbcontrib/log_forwarder/log_forwarder.py Outdated Show resolved Hide resolved
ptbcontrib/log_forwarder/requirements.txt Outdated Show resolved Hide resolved
Copy link
Member

@Bibo-Joshi Bibo-Joshi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates! Just one comment, rest LGTm :)

@@ -0,0 +1 @@
python-telegram-bot>=20.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to be on the safe side, you could use >=20.0,<22.0, but this is okay for me, too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't put much thought into it, I just copied from another module, the log forwarder should work with any version of ptb that has the same signature for send_message, so >=20.0 is good.

Also, sorry for the sloppy first PR and thanks for the suggestions.

@Bibo-Joshi Bibo-Joshi merged commit 8bc77f6 into python-telegram-bot:main Aug 19, 2024
11 checks passed
@Bibo-Joshi
Copy link
Member

Thank you very much for the contribution :)

@Bibo-Joshi
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants