mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-06-17 18:46:40 +00:00
Make logs more consistent
This commit is contained in:
parent
236c2f7e7c
commit
42633882b5
@ -60,7 +60,7 @@ class MessageBox:
|
|||||||
self.next_deadline: Optional[Entry] = None
|
self.next_deadline: Optional[Entry] = None
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace("MessageBox initialized")
|
self._trace("initialized")
|
||||||
|
|
||||||
def _trace(self, msg: str, *args: object) -> None:
|
def _trace(self, msg: str, *args: object) -> None:
|
||||||
# Calls to trace can't really be removed beforehand without some dark magic.
|
# Calls to trace can't really be removed beforehand without some dark magic.
|
||||||
@ -69,7 +69,7 @@ class MessageBox:
|
|||||||
# paying the cost for something that is not used.
|
# paying the cost for something that is not used.
|
||||||
self._logger.log(
|
self._logger.log(
|
||||||
LOG_LEVEL_TRACE,
|
LOG_LEVEL_TRACE,
|
||||||
"Current MessageBox state: seq = %r, date = %s, map = %r",
|
"current state: seq=%r, date=%s, map=%r",
|
||||||
self.seq,
|
self.seq,
|
||||||
self.date.isoformat(),
|
self.date.isoformat(),
|
||||||
self.map,
|
self.map,
|
||||||
@ -79,7 +79,7 @@ class MessageBox:
|
|||||||
def load(self, state: UpdateState) -> None:
|
def load(self, state: UpdateState) -> None:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"Loading MessageBox with state = %r",
|
"loading state: %r",
|
||||||
state,
|
state,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ class MessageBox:
|
|||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"Deadlines met, now getting diff for %r", self.getting_diff_for
|
"deadlines met, now getting diff for: %r", self.getting_diff_for
|
||||||
)
|
)
|
||||||
|
|
||||||
for entry in self.getting_diff_for:
|
for entry in self.getting_diff_for:
|
||||||
@ -184,7 +184,7 @@ class MessageBox:
|
|||||||
|
|
||||||
def set_state(self, state: abcs.updates.State) -> None:
|
def set_state(self, state: abcs.updates.State) -> None:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace("Setting state %s", state)
|
self._trace("setting state: %s", state)
|
||||||
|
|
||||||
deadline = next_updates_deadline()
|
deadline = next_updates_deadline()
|
||||||
assert isinstance(state, types.updates.State)
|
assert isinstance(state, types.updates.State)
|
||||||
@ -197,7 +197,7 @@ class MessageBox:
|
|||||||
|
|
||||||
def try_set_channel_state(self, id: int, pts: int) -> None:
|
def try_set_channel_state(self, id: int, pts: int) -> None:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace("Trying to set channel state for %r: %r", id, pts)
|
self._trace("trying to set channel=%r state: %r", id, pts)
|
||||||
|
|
||||||
if id not in self.map:
|
if id not in self.map:
|
||||||
self.map[id] = State(pts=pts, deadline=next_updates_deadline())
|
self.map[id] = State(pts=pts, deadline=next_updates_deadline())
|
||||||
@ -211,7 +211,9 @@ class MessageBox:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace("Marking %r as needing difference because %s", entry, reason)
|
self._trace(
|
||||||
|
"marking entry=%r as needing difference because: %s", entry, reason
|
||||||
|
)
|
||||||
self.getting_diff_for.add(entry)
|
self.getting_diff_for.add(entry)
|
||||||
self.possible_gaps.pop(entry, None)
|
self.possible_gaps.pop(entry, None)
|
||||||
|
|
||||||
@ -253,7 +255,7 @@ class MessageBox:
|
|||||||
|
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"Processing updates with seq = %r, seq_start = %r, date = %r: %s",
|
"processing updates with seq=%r, seq_start=%r, date=%r: %s",
|
||||||
combined.seq,
|
combined.seq,
|
||||||
combined.seq_start,
|
combined.seq_start,
|
||||||
combined.date,
|
combined.date,
|
||||||
@ -264,7 +266,7 @@ class MessageBox:
|
|||||||
if self.seq + 1 > combined.seq_start:
|
if self.seq + 1 > combined.seq_start:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"Skipping updates as they should have already been handled"
|
"skipping updates as they should have already been handled"
|
||||||
)
|
)
|
||||||
return result, combined.users, combined.chats
|
return result, combined.users, combined.chats
|
||||||
elif self.seq + 1 < combined.seq_start:
|
elif self.seq + 1 < combined.seq_start:
|
||||||
@ -291,7 +293,7 @@ class MessageBox:
|
|||||||
|
|
||||||
if any_pts_applied:
|
if any_pts_applied:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace("Updating seq as local pts was updated too")
|
self._trace("updating seq as local pts was updated too")
|
||||||
self.date = datetime.datetime.fromtimestamp(
|
self.date = datetime.datetime.fromtimestamp(
|
||||||
combined.date, tz=datetime.timezone.utc
|
combined.date, tz=datetime.timezone.utc
|
||||||
)
|
)
|
||||||
@ -301,7 +303,7 @@ class MessageBox:
|
|||||||
if self.possible_gaps:
|
if self.possible_gaps:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"Trying to re-apply %r possible gaps", len(self.possible_gaps)
|
"trying to re-apply count=%r possible gaps", len(self.possible_gaps)
|
||||||
)
|
)
|
||||||
|
|
||||||
for key in list(self.possible_gaps.keys()):
|
for key in list(self.possible_gaps.keys()):
|
||||||
@ -314,7 +316,7 @@ class MessageBox:
|
|||||||
result.append(applied)
|
result.append(applied)
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"Resolved gap with %r: %s",
|
"resolved gap with pts=%r: %s",
|
||||||
pts_info_from_update(applied),
|
pts_info_from_update(applied),
|
||||||
applied,
|
applied,
|
||||||
)
|
)
|
||||||
@ -337,14 +339,15 @@ class MessageBox:
|
|||||||
if not pts:
|
if not pts:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"No pts in update, so it can be applied in any order: %s", update
|
"no pts in update, so it can be applied in any order: %s", update
|
||||||
)
|
)
|
||||||
return None, update
|
return None, update
|
||||||
|
|
||||||
if pts.entry in self.getting_diff_for:
|
if pts.entry in self.getting_diff_for:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"Skipping update with %r as its difference is being fetched", pts
|
"skipping update with pts=%r as its difference is being fetched",
|
||||||
|
pts,
|
||||||
)
|
)
|
||||||
return pts.entry, None
|
return pts.entry, None
|
||||||
|
|
||||||
@ -353,7 +356,7 @@ class MessageBox:
|
|||||||
if local_pts + pts.pts_count > pts.pts:
|
if local_pts + pts.pts_count > pts.pts:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"Skipping update since local pts %r > %r: %s",
|
"skipping update since local-pts=%r > pts=%r: %s",
|
||||||
local_pts,
|
local_pts,
|
||||||
pts,
|
pts,
|
||||||
update,
|
update,
|
||||||
@ -362,7 +365,7 @@ class MessageBox:
|
|||||||
elif local_pts + pts.pts_count < pts.pts:
|
elif local_pts + pts.pts_count < pts.pts:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"Possible gap since local pts %r < %r: %s",
|
"possible gap since local-pts=%r < pts=%r: %s",
|
||||||
local_pts,
|
local_pts,
|
||||||
pts,
|
pts,
|
||||||
update,
|
update,
|
||||||
@ -379,7 +382,7 @@ class MessageBox:
|
|||||||
else:
|
else:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace(
|
self._trace(
|
||||||
"Applying update pts since local pts %r = %r: %s",
|
"applying update pts since local-pts=%r = pts=%r: %s",
|
||||||
local_pts,
|
local_pts,
|
||||||
pts,
|
pts,
|
||||||
update,
|
update,
|
||||||
@ -413,7 +416,7 @@ class MessageBox:
|
|||||||
qts_limit=None,
|
qts_limit=None,
|
||||||
)
|
)
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace("Requesting account difference %s", gd)
|
self._trace("requesting account difference: %s", gd)
|
||||||
return gd
|
return gd
|
||||||
|
|
||||||
return None
|
return None
|
||||||
@ -424,7 +427,7 @@ class MessageBox:
|
|||||||
chat_hashes: ChatHashCache,
|
chat_hashes: ChatHashCache,
|
||||||
) -> Tuple[List[abcs.Update], List[abcs.User], List[abcs.Chat]]:
|
) -> Tuple[List[abcs.Update], List[abcs.User], List[abcs.Chat]]:
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace("Applying account difference %s", diff)
|
self._trace("applying account difference: %s", diff)
|
||||||
|
|
||||||
finish: bool
|
finish: bool
|
||||||
result: Tuple[List[abcs.Update], List[abcs.User], List[abcs.Chat]]
|
result: Tuple[List[abcs.Update], List[abcs.User], List[abcs.Chat]]
|
||||||
@ -548,11 +551,11 @@ class MessageBox:
|
|||||||
else USER_CHANNEL_DIFF_LIMIT,
|
else USER_CHANNEL_DIFF_LIMIT,
|
||||||
)
|
)
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace("Requesting channel difference %s", gd)
|
self._trace("requesting channel difference: %s", gd)
|
||||||
return gd
|
return gd
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"Should not try to get difference for an entry without known state"
|
"should not try to get difference for an entry without known state"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.end_get_diff(entry)
|
self.end_get_diff(entry)
|
||||||
@ -567,7 +570,7 @@ class MessageBox:
|
|||||||
) -> Tuple[List[abcs.Update], List[abcs.User], List[abcs.Chat]]:
|
) -> Tuple[List[abcs.Update], List[abcs.User], List[abcs.Chat]]:
|
||||||
entry: Entry = channel_id
|
entry: Entry = channel_id
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace("Applying channel difference for %r: %s", entry, diff)
|
self._trace("applying channel=%r difference: %s", entry, diff)
|
||||||
|
|
||||||
self.possible_gaps.pop(entry, None)
|
self.possible_gaps.pop(entry, None)
|
||||||
|
|
||||||
@ -624,7 +627,7 @@ class MessageBox:
|
|||||||
) -> None:
|
) -> None:
|
||||||
entry: Entry = channel_id
|
entry: Entry = channel_id
|
||||||
if __debug__:
|
if __debug__:
|
||||||
self._trace("Ending channel difference for %r because %s", entry, reason)
|
self._trace("ending channel=%r difference: %s", entry, reason)
|
||||||
|
|
||||||
if reason == PrematureEndReason.TEMPORARY_SERVER_ISSUES:
|
if reason == PrematureEndReason.TEMPORARY_SERVER_ISSUES:
|
||||||
self.possible_gaps.pop(entry, None)
|
self.possible_gaps.pop(entry, None)
|
||||||
@ -634,4 +637,4 @@ class MessageBox:
|
|||||||
self.end_get_diff(entry)
|
self.end_get_diff(entry)
|
||||||
del self.map[entry]
|
del self.map[entry]
|
||||||
else:
|
else:
|
||||||
raise RuntimeError("Unknown reason to end channel difference")
|
raise RuntimeError("unknown reason to end channel difference")
|
||||||
|
Loading…
Reference in New Issue
Block a user