Skip to content

antos07/aiogram-loguru

Repository files navigation

aiogram-loguru

PyPI - License PyPI - Status PyPI - Version PyPI - Python Version

aiogram-loguru is a small library that ships some boilerplate code needed for integrating aiogram with loguru.

Features

  • A sink for loguru that sends logs to a Telegram chat via a bot.
  • and more features soon...

Requirements

Python 3.9+ is supported. It also requires aiogram (v3.18 or later) and loguru (v0.7.0 or later) to be installed.

Installation

pip install aiogram-loguru

Usage

You can use the sink like this:

from aiogram import Bot
from aiogram_loguru import AiogramSink
from loguru import logger

CHAT_ID = 12345  # the ID of a chat, where the logs will be sent to

bot = Bot("YOUR BOT TOKEN")
sink = AiogramSink(bot, CHAT_ID)
logger.add(sink)

Now all the logs will be sent to the selected Telegram chat. However, Telegram Bot API has rather painful limits, so you would probably want to limit the number of sent logs to the most important ones like this:

logger.add(sink, level='ERROR')

Lastly, for the sink to work, you should actually have an event loop running. You should also await logger.complete() when your program is exiting to ensure that all logs have been actually sent. See the docs for details.

License

This project is licensed under the terms of the MIT license.

About

aiogram-loguru is a small library that ships some boilerplate code needed for integrating aiogram with loguru.

Topics

Resources

License

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages