2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-22 09:57:19 +00:00

Optimize log calls

This commit is contained in:
Dan 2022-12-26 16:38:12 +01:00
parent d298c62c6d
commit 01cd8bb57f
8 changed files with 35 additions and 35 deletions

View File

@ -396,7 +396,7 @@ class Client(Methods):
except BadRequest as e:
print(e.MESSAGE)
except Exception as e:
log.error(e, exc_info=True)
log.exception(e)
raise
else:
self.password = None
@ -684,11 +684,11 @@ class Client(Methods):
try:
module = import_module(module_path)
except ImportError:
log.warning(f'[{self.name}] [LOAD] Ignoring non-existent module "{module_path}"')
log.warning('[%s] [LOAD] Ignoring non-existent module "%s"', self.name, module_path)
continue
if "__path__" in dir(module):
log.warning(f'[{self.name}] [LOAD] Ignoring namespace "{module_path}"')
log.warning('[%s] [LOAD] Ignoring namespace "%s"', self.name, module_path)
continue
if handlers is None:
@ -719,11 +719,11 @@ class Client(Methods):
try:
module = import_module(module_path)
except ImportError:
log.warning(f'[{self.name}] [UNLOAD] Ignoring non-existent module "{module_path}"')
log.warning('[%s] [UNLOAD] Ignoring non-existent module "%s"', self.name, module_path)
continue
if "__path__" in dir(module):
log.warning(f'[{self.name}] [UNLOAD] Ignoring namespace "{module_path}"')
log.warning('[%s] [UNLOAD] Ignoring namespace "%s"', self.name, module_path)
continue
if handlers is None:
@ -750,7 +750,7 @@ class Client(Methods):
log.info('[{}] Successfully loaded {} plugin{} from "{}"'.format(
self.name, count, "s" if count > 1 else "", root))
else:
log.warning(f'[{self.name}] No plugin loaded from "{root}"')
log.warning('[%s] No plugin loaded from "%s"', self.name, root)
async def handle_download(self, packet):
file_id, directory, file_name, in_memory, file_size, progress, progress_args = packet
@ -1012,7 +1012,7 @@ class Client(Methods):
except pyrogram.StopTransmission:
raise
except Exception as e:
log.error(e, exc_info=True)
log.exception(e)
def guess_mime_type(self, filename: str) -> Optional[str]:
return self.mimetypes.guess_type(filename)[0]

View File

@ -151,7 +151,7 @@ class Dispatcher:
self.loop.create_task(self.handler_worker(self.locks_list[-1]))
)
log.info(f"Started {self.client.workers} HandlerTasks")
log.info("Started %s HandlerTasks", self.client.workers)
async def stop(self):
if not self.client.no_updates:
@ -164,7 +164,7 @@ class Dispatcher:
self.handler_worker_tasks.clear()
self.groups.clear()
log.info(f"Stopped {self.client.workers} HandlerTasks")
log.info("Stopped %s HandlerTasks", self.client.workers)
def add_handler(self, handler, group: int):
async def fn():
@ -226,7 +226,7 @@ class Dispatcher:
if await handler.check(self.client, parsed_update):
args = (parsed_update,)
except Exception as e:
log.error(e, exc_info=True)
log.exception(e)
continue
elif isinstance(handler, RawUpdateHandler):
@ -250,10 +250,10 @@ class Dispatcher:
except pyrogram.ContinuePropagation:
continue
except Exception as e:
log.error(e, exc_info=True)
log.exception(e)
break
except pyrogram.StopPropagation:
pass
except Exception as e:
log.error(e, exc_info=True)
log.exception(e)

View File

@ -107,7 +107,7 @@ class SaveFile:
try:
await session.invoke(data)
except Exception as e:
log.error(e)
log.exception(e)
part_size = 512 * 1024
@ -201,7 +201,7 @@ class SaveFile:
except StopTransmission:
raise
except Exception as e:
log.error(e, exc_info=True)
log.exception(e)
else:
if is_big:
return raw.types.InputFileBig(

View File

@ -41,7 +41,7 @@ class Terminate:
if self.takeout_id:
await self.invoke(raw.functions.account.FinishTakeoutSession())
log.warning(f"Takeout session {self.takeout_id} finished")
log.warning("Takeout session %s finished", self.takeout_id)
await self.storage.save()
await self.dispatcher.stop()

View File

@ -63,7 +63,7 @@ class Start:
if not await self.storage.is_bot() and self.takeout:
self.takeout_id = (await self.invoke(raw.functions.account.InitTakeoutSession())).id
log.warning(f"Takeout session {self.takeout_id} initiated")
log.warning("Takeout session %s initiated", self.takeout_id)
await self.invoke(raw.functions.updates.GetState())
except (Exception, KeyboardInterrupt):

View File

@ -103,7 +103,7 @@ class Parser(HTMLParser):
line, offset = self.getpos()
offset += 1
log.debug(f"Unmatched closing tag </{tag}> at line {line}:{offset}")
log.debug("Unmatched closing tag </%s> at line %s:%s", tag, line, offset)
else:
if not self.tag_entities[tag]:
self.tag_entities.pop(tag)
@ -131,7 +131,7 @@ class HTML:
for tag, entities in parser.tag_entities.items():
unclosed_tags.append(f"<{tag}> (x{len(entities)})")
log.warning(f"Unclosed tags: {', '.join(unclosed_tags)}")
log.warning("Unclosed tags: %s", ", ".join(unclosed_tags))
entities = []

View File

@ -79,34 +79,34 @@ class Auth:
self.connection = Connection(self.dc_id, self.test_mode, self.ipv6, self.proxy)
try:
log.info(f"Start creating a new auth key on DC{self.dc_id}")
log.info("Start creating a new auth key on DC%s", self.dc_id)
await self.connection.connect()
# Step 1; Step 2
nonce = int.from_bytes(urandom(16), "little", signed=True)
log.debug(f"Send req_pq: {nonce}")
log.debug("Send req_pq: %s", nonce)
res_pq = await self.invoke(raw.functions.ReqPqMulti(nonce=nonce))
log.debug(f"Got ResPq: {res_pq.server_nonce}")
log.debug(f"Server public key fingerprints: {res_pq.server_public_key_fingerprints}")
log.debug("Got ResPq: %s", res_pq.server_nonce)
log.debug("Server public key fingerprints: %s", res_pq.server_public_key_fingerprints)
for i in res_pq.server_public_key_fingerprints:
if i in rsa.server_public_keys:
log.debug(f"Using fingerprint: {i}")
log.debug("Using fingerprint: %s", i)
public_key_fingerprint = i
break
else:
log.debug(f"Fingerprint unknown: {i}")
log.debug("Fingerprint unknown: %s", i)
else:
raise Exception("Public key not found")
# Step 3
pq = int.from_bytes(res_pq.pq, "big")
log.debug(f"Start PQ factorization: {pq}")
log.debug("Start PQ factorization: %s", pq)
start = time.time()
g = prime.decompose(pq)
p, q = sorted((g, pq // g)) # p < q
log.debug(f"Done PQ factorization ({round(time.time() - start, 3)}s): {p} {q}")
log.debug("Done PQ factorization (%ss): %s %s", round(time.time() - start, 3), p, q)
# Step 4
server_nonce = res_pq.server_nonce
@ -168,7 +168,7 @@ class Auth:
dh_prime = int.from_bytes(server_dh_inner_data.dh_prime, "big")
delta_time = server_dh_inner_data.server_time - time.time()
log.debug(f"Delta time: {round(delta_time, 3)}")
log.debug("Delta time: %s", round(delta_time, 3))
# Step 6
g = server_dh_inner_data.g
@ -262,11 +262,11 @@ class Auth:
# Step 9
server_salt = aes.xor(new_nonce[:8], server_nonce[:8])
log.debug(f"Server salt: {int.from_bytes(server_salt, 'little')}")
log.debug("Server salt: %s", int.from_bytes(server_salt, "little"))
log.info(f"Done auth key exchange: {set_client_dh_params_answer.__class__.__name__}")
log.info("Done auth key exchange: %s", set_client_dh_params_answer.__class__.__name__)
except Exception as e:
log.info(f"Retrying due to {type(e).__name__}: {e}")
log.info("Retrying due to %s: %s", type(e).__name__, e)
if retries_left:
retries_left -= 1

View File

@ -3045,13 +3045,13 @@ class Message(Object, Update):
RPCError: In case of a Telegram RPC error.
"""
if self.service:
log.warning(f"Service messages cannot be copied. "
f"chat_id: {self.chat.id}, message_id: {self.id}")
log.warning("Service messages cannot be copied. chat_id: %s, message_id: %s",
self.chat.id, self.id)
elif self.game and not await self._client.storage.is_bot():
log.warning(f"Users cannot send messages with Game media type. "
f"chat_id: {self.chat.id}, message_id: {self.id}")
log.warning("Users cannot send messages with Game media type. chat_id: %s, message_id: %s",
self.chat.id, self.id)
elif self.empty:
log.warning(f"Empty messages cannot be copied. ")
log.warning("Empty messages cannot be copied.")
elif self.text:
return await self._client.send_message(
chat_id,