1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00

Use existing record for building ident

This commit is contained in:
Unrud 2023-03-21 16:48:39 +01:00 committed by Unrud
parent a2be03fdaf
commit 8efb942892

View file

@ -65,15 +65,17 @@ class IdentLogRecordFactory:
def __call__(self, *args: Any, **kwargs: Any) -> logging.LogRecord: def __call__(self, *args: Any, **kwargs: Any) -> logging.LogRecord:
record = self._upstream_factory(*args, **kwargs) record = self._upstream_factory(*args, **kwargs)
ident = "%d" % os.getpid() ident = ("%d" % record.process if record.process is not None
main_thread = threading.main_thread() else record.processName or "unknown")
current_thread = threading.current_thread() tid = None
if current_thread.name and main_thread != current_thread: if record.thread is not None:
ident += "/%s" % current_thread.name if record.thread != threading.main_thread().ident:
ident += "/%s" % (record.threadName or "unknown")
if (sys.version_info >= (3, 8) and
record.thread == threading.get_ident()):
tid = threading.get_native_id()
record.ident = ident # type:ignore[attr-defined] record.ident = ident # type:ignore[attr-defined]
record.tid = None # type:ignore[attr-defined] record.tid = tid # type:ignore[attr-defined]
if sys.version_info >= (3, 8):
record.tid = current_thread.native_id
return record return record