Add TID and SYSLOG_{IDENTIFIER,FACILITY,PID} to log messages

Systemd journal entries have several common entries:
https://www.freedesktop.org/software/systemd/man/latest/systemd.journal-fields.html

Add "SYSLOG_IDENTIFIER" to make it easier to find wireplumber messages.
Add "SYSLOG_FACILITY" to avoid confusing programs that expect both or neither.
Add "TID" and "SYSLOG_PID" to make debugging a little easier.
This commit is contained in:
Andrew Sayers 2025-04-18 15:14:34 +01:00
parent 08d7e51efb
commit 2a5606e437
No known key found for this signature in database
GPG key ID: D44E183E68ABF38D
2 changed files with 23 additions and 1 deletions

View file

@ -772,10 +772,17 @@ wp_log_fields_write_to_stream (WpLogFields *lf, FILE *s)
static gboolean
wp_log_fields_write_to_journal (WpLogFields *lf)
{
GLogField fields[6];
GLogField fields[10];
gsize n_fields = 0;
g_autofree gchar *full_message = NULL;
const gchar *message = lf->message ? lf->message : "";
g_autofree gchar *pid = g_strdup_printf("%d", getpid());
g_autofree gchar *tid = g_strdup_printf("%d", gettid());
#ifdef HAS_SHORT_NAME
const gchar *syslog_identifier = program_invocation_short_name;
#else
const gchar *syslog_identifier = g_get_prgname();
#endif
if (lf->debug) {
if (lf->file && lf->line && lf->func) {
@ -797,6 +804,10 @@ wp_log_fields_write_to_journal (WpLogFields *lf)
message = full_message = g_strdup_printf("%s: %s", lf->log_topic, message);
}
fields[n_fields++] = (GLogField) { "SYSLOG_PID", pid, -1 };
fields[n_fields++] = (GLogField) { "TID", tid, -1 };
fields[n_fields++] = (GLogField) { "SYSLOG_IDENTIFIER", syslog_identifier, -1 };
fields[n_fields++] = (GLogField) { "SYSLOG_FACILITY", "3", -1 };
fields[n_fields++] = (GLogField) { "PRIORITY", log_level_info[lf->log_level].priority, -1 };
if (lf->file)
fields[n_fields++] = (GLogField) { "CODE_FILE", lf->file, -1 };

View file

@ -42,6 +42,17 @@ add_project_arguments([
], language: 'c'
)
check_short_name = '''#define _GNU_SOURCE
#include <errno.h>
void main() { program_invocation_short_name; }
'''
if cc.compiles(check_short_name, name : 'check short_name')
add_project_arguments([
'-DHAS_SHORT_NAME',
], language: 'c'
)
endif
build_modules = get_option('modules')
build_daemon = get_option('daemon')
if build_daemon and not build_modules