aiogram-loguru is a small library that ships some boilerplate code needed for integrating aiogram with loguru.
- A sink for loguru that sends logs to a Telegram chat via a bot.
- and more features soon...
Python 3.9+ is supported. It also requires aiogram (v3.18 or later) and loguru (v0.7.0 or later) to be installed.
pip install aiogram-loguru
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.
This project is licensed under the terms of the MIT license.