Make logger fully configurable (#1087)

This commit is contained in:
Tulir Asokan
2019-01-11 16:52:30 +02:00
committed by Lonami
parent eda4178333
commit f271316d7d
15 changed files with 141 additions and 137 deletions

View File

@@ -1,7 +1,5 @@
import asyncio
import inspect
import itertools
import logging
import random
import time
@@ -9,8 +7,6 @@ from .users import UserMethods
from .. import events, utils, errors
from ..tl import types, functions
__log__ = logging.getLogger(__name__)
class UpdateMethods(UserMethods):
@@ -281,28 +277,31 @@ class UpdateMethods(UserMethods):
await callback(event)
except errors.AlreadyInConversationError:
name = getattr(callback, '__name__', repr(callback))
__log__.debug('Event handler "%s" already has an open '
'conversation, ignoring new one', name)
self._log[__name__].debug(
'Event handler "%s" already has an open conversation, '
'ignoring new one', name)
except events.StopPropagation:
name = getattr(callback, '__name__', repr(callback))
__log__.debug(
self._log[__name__].debug(
'Event handler "%s" stopped chain of propagation '
'for event %s.', name, type(event).__name__
)
break
except Exception:
name = getattr(callback, '__name__', repr(callback))
__log__.exception('Unhandled exception on %s', name)
self._log[__name__].exception('Unhandled exception on %s',
name)
async def _handle_auto_reconnect(self):
# Upon reconnection, we want to send getState
# for Telegram to keep sending us updates.
try:
__log__.info('Asking for the current state after reconnect...')
self._log[__name__].info(
'Asking for the current state after reconnect...')
state = await self(functions.updates.GetStateRequest())
__log__.info('Got new state! %s', state)
self._log[__name__].info('Got new state! %s', state)
except errors.RPCError as e:
__log__.info('Failed to get current state: %r', e)
self._log[__name__].info('Failed to get current state: %r', e)
# endregion