mirror of
https://github.com/aiogram/aiogram.git
synced 2025-12-17 12:34:39 +00:00
Add logging for receiving updates
This commit is contained in:
parent
334975bf21
commit
93a330c1f2
3 changed files with 33 additions and 1 deletions
|
|
@ -1,8 +1,21 @@
|
||||||
from .api import methods, types
|
from .api import methods, types
|
||||||
from .api.client import session
|
from .api.client import session
|
||||||
from .api.client.bot import Bot
|
from .api.client.bot import Bot
|
||||||
|
from .dispatcher import filters
|
||||||
|
from .dispatcher.dispatcher import Dispatcher
|
||||||
|
from .dispatcher.router import Router
|
||||||
|
|
||||||
__all__ = ("__api_version__", "__version__", "types", "methods", "Bot", "session")
|
__all__ = (
|
||||||
|
"__api_version__",
|
||||||
|
"__version__",
|
||||||
|
"types",
|
||||||
|
"methods",
|
||||||
|
"Bot",
|
||||||
|
"session",
|
||||||
|
"Dispatcher",
|
||||||
|
"Router",
|
||||||
|
"filters",
|
||||||
|
)
|
||||||
|
|
||||||
__version__ = "3.0.0a0"
|
__version__ = "3.0.0a0"
|
||||||
__api_version__ = "4.4"
|
__api_version__ = "4.4"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
|
import asyncio
|
||||||
from typing import AsyncGenerator, Optional
|
from typing import AsyncGenerator, Optional
|
||||||
|
|
||||||
|
from .. import loggers
|
||||||
from ..api.client.bot import Bot
|
from ..api.client.bot import Bot
|
||||||
from ..api.methods import TelegramMethod
|
from ..api.methods import TelegramMethod
|
||||||
from ..api.types import Update
|
from ..api.types import Update
|
||||||
|
|
@ -24,9 +26,23 @@ class Dispatcher(Router):
|
||||||
:param update:
|
:param update:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
loop = asyncio.get_running_loop()
|
||||||
|
handled = False
|
||||||
|
start_time = loop.time()
|
||||||
|
|
||||||
Bot.set_current(bot)
|
Bot.set_current(bot)
|
||||||
async for result in self.update_handler.trigger(update, bot=bot, **kwargs):
|
async for result in self.update_handler.trigger(update, bot=bot, **kwargs):
|
||||||
yield result
|
yield result
|
||||||
|
handled = True
|
||||||
|
|
||||||
|
finish_time = loop.time()
|
||||||
|
duration = (finish_time - start_time) * 1000
|
||||||
|
loggers.dispatcher.info(
|
||||||
|
"Update id=%s is %s. Duration %d ms.",
|
||||||
|
update.update_id,
|
||||||
|
"handled" if handled else "not handled",
|
||||||
|
duration,
|
||||||
|
)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def listen_updates(cls, bot: Bot) -> AsyncGenerator[Update, None]:
|
async def listen_updates(cls, bot: Bot) -> AsyncGenerator[Update, None]:
|
||||||
|
|
|
||||||
3
aiogram/loggers.py
Normal file
3
aiogram/loggers.py
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
dispatcher = logging.getLogger("aiogram.dispatcher")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue