Skip to content

Commit

Permalink
better logger implementation & small fix
Browse files Browse the repository at this point in the history
  • Loading branch information
99oblivius committed Jul 24, 2024
1 parent 0e667fb commit d5d0295
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/matches/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,12 @@ def server_score(server_region):
await self.increment_state()

if check_state(MatchState.MATCH_WAIT_FOR_END):
self.match = await self.bot.store.get_match(self.match_id)
team_scores = [0, 0]
users_match_stats = {}
last_users_match_stats = {}
disconnection_tracker = { player.user_id: 0 for player in self.players }
last_round_number = self.match.a_score + self.match.b_score
last_round_number = self.match.a_score + self.match.b_score if self.match.a_score else 0
abandoned_users = []
changed_users = {}
players_dict = {}
Expand Down
2 changes: 2 additions & 0 deletions src/utils/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def log_db_operation(func: Callable) -> Callable:
async def wrapper(*args, **kwargs):
start_time = time.time()
result = await func(*args, **kwargs)
if log.get_level() > log.DEBUG:
return result
end_time = time.time()
execution_time = end_time - start_time

Expand Down
19 changes: 12 additions & 7 deletions src/utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,22 +74,27 @@ def _get_timestamp():
def _get_caller_class():
current_frame = inspect.currentframe()
try:
for _ in range(3): # Skip Logger frames
for _ in range(3):
if current_frame is not None:
current_frame = current_frame.f_back

if current_frame is not None:
frame_info = inspect.getframeinfo(current_frame)
module = inspect.getmodule(current_frame)
if module:
class_name = None
for name, obj in module.__dict__.items():
if inspect.isclass(obj):
for attr, value in obj.__dict__.items():
if getattr(value, '__code__', None) is current_frame.f_code:
return obj.__name__
return frame_info.function
if current_frame.f_code in [func.__code__ for func in obj.__dict__.values() if callable(func)]:
return obj.__name__
elif class_name is None:
class_name = obj.__name__

if class_name:
return f"Global: {class_name}"

return "Global"
finally:
del current_frame # Avoid reference cycles
del current_frame

return ''

Expand Down

0 comments on commit d5d0295

Please sign in to comment.