diff --git a/telethon/client/telegrambaseclient.py b/telethon/client/telegrambaseclient.py index 03d201b0..bea10cbe 100644 --- a/telethon/client/telegrambaseclient.py +++ b/telethon/client/telegrambaseclient.py @@ -25,8 +25,7 @@ DEFAULT_PORT = 443 if typing.TYPE_CHECKING: from .telegramclient import TelegramClient -__default_log__ = logging.getLogger(__base_name__) -__default_log__.addHandler(logging.NullHandler()) +_base_log = logging.getLogger(__base_name__) # In seconds, how long to wait before disconnecting a exported sender. @@ -246,7 +245,7 @@ class TelegramBaseClient(abc.ABC): if isinstance(base_logger, str): base_logger = logging.getLogger(base_logger) elif not isinstance(base_logger, logging.Logger): - base_logger = __default_log__ + base_logger = _base_log class _Loggers(dict): def __missing__(self, key): diff --git a/telethon/client/updates.py b/telethon/client/updates.py index 7d009ffe..a9d6344e 100644 --- a/telethon/client/updates.py +++ b/telethon/client/updates.py @@ -284,16 +284,6 @@ class UpdateMethods: # region Private methods - def _log_exc(self: 'TelegramClient', msg, *args): - """ - Log an exception, using `stderr` if `logging` is not configured. - """ - if logging.root.hasHandlers(): - self._log[__name__].exception(msg, *args) - else: - print('[ERROR/telethon]:', msg % args, file=sys.stderr) - traceback.print_exc() - # It is important to not make _handle_update async because we rely on # the order that the updates arrive in to update the pts and date to # be always-increasing. There is also no need to make this async. @@ -477,7 +467,7 @@ class UpdateMethods: except Exception as e: if not isinstance(e, asyncio.CancelledError) or self.is_connected(): name = getattr(callback, '__name__', repr(callback)) - self._log_exc('Unhandled exception on %s', name) + self._log[__name__].exception('Unhandled exception on %s', name) async def _dispatch_event(self: 'TelegramClient', event): """ @@ -518,7 +508,7 @@ class UpdateMethods: except Exception as e: if not isinstance(e, asyncio.CancelledError) or self.is_connected(): name = getattr(callback, '__name__', repr(callback)) - self._log_exc('Unhandled exception on %s', name) + self._log[__name__].exception('Unhandled exception on %s', name) async def _get_difference(self: 'TelegramClient', update, channel_id, pts_date): """ @@ -621,7 +611,8 @@ class UpdateMethods: self._log[__name__].warning('Failed to get missed updates after ' 'reconnect: %r', e) except Exception: - self._log_exc('Unhandled exception while getting update difference after reconnect') + self._log[__name__].exception( + 'Unhandled exception while getting update difference after reconnect') # endregion