Log thread name when not main thread

This commit is contained in:
Unrud 2018-08-18 16:43:18 +02:00
parent b8627c33fb
commit af831ff13f

View File

@ -57,17 +57,17 @@ class IdentLogRecordFactory:
def __init__(self, upstream_factory): def __init__(self, upstream_factory):
self.upstream_factory = upstream_factory self.upstream_factory = upstream_factory
self.main_pid = os.getpid() self.main_pid = os.getpid()
self.main_thread_name = threading.current_thread().name
def __call__(self, *args, **kwargs): def __call__(self, *args, **kwargs):
record = self.upstream_factory(*args, **kwargs) record = self.upstream_factory(*args, **kwargs)
pid = os.getpid() pid = os.getpid()
thread_name = threading.current_thread().name
ident = "%x" % self.main_pid ident = "%x" % self.main_pid
if pid != self.main_pid: if pid != self.main_pid:
ident += "%+x" % (pid - self.main_pid) ident += "%+x" % (pid - self.main_pid)
if thread_name != self.main_thread_name: main_thread = threading.main_thread()
ident += "/%s" % thread_name current_thread = threading.current_thread()
if current_thread.name and main_thread != current_thread:
ident += "/%s" % current_thread.name
record.ident = ident record.ident = ident
return record return record