Print PID in debug logs.

So one can easily see if there are two instances running, if they are
logging to the same file.

Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
Steffen Jaeckel
2025-10-10 10:43:04 +02:00
parent 2fb56b8536
commit 1aeb19acb0

View File

@@ -60,6 +60,7 @@ static FILE* logp;
static gchar* mainlogfile = NULL; static gchar* mainlogfile = NULL;
static gboolean user_provided_log = FALSE; static gboolean user_provided_log = FALSE;
static log_level_t level_filter; static log_level_t level_filter;
static pid_t prof_pid;
static int stderr_inited; static int stderr_inited;
static log_level_t stderr_level; static log_level_t stderr_level;
@@ -198,6 +199,8 @@ log_init(log_level_t filter, char* log_file)
logp = fopen(mainlogfile, "a"); logp = fopen(mainlogfile, "a");
g_chmod(mainlogfile, S_IRUSR | S_IWUSR); g_chmod(mainlogfile, S_IRUSR | S_IWUSR);
prof_pid = getpid();
} }
const gchar* const gchar*
@@ -231,7 +234,7 @@ _log_msg(log_level_t level, const char* const area, const char* const msg)
auto_gchar gchar* date_fmt = g_date_time_format_iso8601(dt); auto_gchar gchar* date_fmt = g_date_time_format_iso8601(dt);
fprintf(logp, "%s: %s: %s: %s\n", date_fmt, area, level_str, msg); fprintf(logp, "%s: %08d: %s: %s: %s\n", date_fmt, prof_pid, area, level_str, msg);
g_date_time_unref(dt); g_date_time_unref(dt);
fflush(logp); fflush(logp);