From d93135acd813c8e467938afcbb535ccdd614947e Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Wed, 15 May 2024 09:36:22 -0400 Subject: [PATCH] Include truncated `id(trio.Task)` for task info in log header --- tractor/log.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tractor/log.py b/tractor/log.py index f7d6a32..78611f2 100644 --- a/tractor/log.py +++ b/tractor/log.py @@ -202,8 +202,19 @@ class StackLevelAdapter(LoggerAdapter): ) +def pformat_task_uid(): + ''' + Return `str`-ified unique for a `trio.Task` via a combo of its + `.name: str` and `id()` truncated output. + + ''' + task: trio.Task = trio.lowlevel.current_task() + tid: str = str(id(task)) + return f'{task.name}[{tid[:6]}]' + + _conc_name_getters = { - 'task': lambda: trio.lowlevel.current_task().name, + 'task': pformat_task_uid, 'actor': lambda: current_actor(), 'actor_name': lambda: current_actor().name, 'actor_uid': lambda: current_actor().uid[1][:6], @@ -211,7 +222,10 @@ _conc_name_getters = { class ActorContextInfo(Mapping): - "Dyanmic lookup for local actor and task names" + ''' + Dyanmic lookup for local actor and task names. + + ''' _context_keys = ( 'task', 'actor',