Add base_logger docs and make _log dict dynamic

This commit is contained in:
Tulir Asokan 2019-01-11 15:50:39 +02:00
parent 1d764f3f16
commit 54076f32fd

View File

@ -134,6 +134,15 @@ class TelegramBaseClient(abc.ABC):
system_lang_code (`str`, optional): system_lang_code (`str`, optional):
"System lang code" to be sent when creating the initial connection. "System lang code" to be sent when creating the initial connection.
Defaults to `lang_code`. Defaults to `lang_code`.
loop (`asyncio.AbstractEventLoop`, optional):
Asyncio event loop to use. Defaults to `asyncio.get_event_loop()`
base_logger (`str` | `logging.Logger`, optional):
Base logger name or instance to use.
If a `str` is given, it'll be passed to `logging.getLogger()`. If a
`logging.Logger` is given, it'll be used directly. If something
else or nothing is given, the default logger will be used.
""" """
# Current TelegramClient version # Current TelegramClient version
@ -176,12 +185,14 @@ class TelegramBaseClient(abc.ABC):
base_logger = logging.getLogger(base_logger) base_logger = logging.getLogger(base_logger)
elif not isinstance(base_logger, logging.Logger): elif not isinstance(base_logger, logging.Logger):
base_logger = __default_log__ base_logger = __default_log__
subloggers = ["client.updates", "client.users", "client.downloads",
"network.mtprotosender", "network.mtprotostate", class _Loggers(dict):
"network.connection.connection", def __missing__(self, key):
"extensions.messagepacker"] if key.startswith("telethon."):
self._log = {"telethon.{}".format(name): base_logger.getChild(name) key = key[len("telethon."):]
for name in subloggers} return base_logger.getChild(key)
self._log = _Loggers()
# Determine what session object we have # Determine what session object we have
if isinstance(session, str) or session is None: if isinstance(session, str) or session is None: