spa: support: logger: print thread id for each message

The thread id is very useful for debugging, add it to the every log
message so that it does not have to be inferred from the content itself.

This is already done in the systemd journal logger, so implement
it here as well.

Before:

  [I][00:13:11.120303] pw.context   | [      pipewire.c:  585 pw_init()] version 1.7.0

After:

  [I][365073][00:13:11.120303] pw.context   | [      pipewire.c:  585 pw_init()] version 1.7.0
This commit is contained in:
Barnabás Pőcze 2026-03-12 00:21:08 +01:00
parent 95eac7b4e5
commit 3273ba6333

View file

@ -2,12 +2,16 @@
/* SPDX-FileCopyrightText: Copyright © 2018 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#include "config.h"
#include <stddef.h>
#include <stdint.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <time.h>
#include <threads.h>
#include <fnmatch.h>
#include <spa/support/log.h>
@ -92,6 +96,14 @@ impl_log_logtv(void *object,
spa_strbuf_append(&msg, "%s[%s]", prefix, levels[level]);
#ifdef HAVE_GETTID
static thread_local pid_t tid;
if (SPA_UNLIKELY(tid == 0))
tid = gettid();
spa_strbuf_append(&msg, "[%jd]", (intmax_t) tid);
#endif
if (impl->local_timestamp) {
char buf[64];
struct timespec now;