From 76985faa118835e1b8ee2e5fb8ce51631d90ffd4 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Fri, 20 Nov 2020 01:53:19 +0100 Subject: [PATCH] Evaluate debug raw data only when actually needed #541 --- pyrogram/session/session.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pyrogram/session/session.py b/pyrogram/session/session.py index 3aecaab3..490eea54 100644 --- a/pyrogram/session/session.py +++ b/pyrogram/session/session.py @@ -243,7 +243,10 @@ class Session: else [data] ) - log.debug(f"Received:\n{data}") + # Call log.debug twice because calling it once by appending "data" to the previous string (i.e. f"Kind: {data}") + # will cause "data" to be evaluated as string every time instead of only when debug is actually enabled. + log.debug("Received:") + log.debug(data) for msg in messages: if msg.seq_no == 0: @@ -367,7 +370,10 @@ class Session: if wait_response: self.results[msg_id] = Result() - log.debug(f"Sent:\n{message}") + # Call log.debug twice because calling it once by appending "data" to the previous string (i.e. f"Kind: {data}") + # will cause "data" to be evaluated as string every time instead of only when debug is actually enabled. + log.debug(f"Sent:") + log.debug(message) if len(message) <= self.EXECUTOR_SIZE_THRESHOLD: payload = mtproto.pack(