From 75a49f845d5fd4a2d763764a11a0eed06a94dcdd Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 7 Feb 2025 11:40:45 +0000 Subject: [PATCH] job: Send timestamp when streaming the log Signed-off-by: Michael Tremer --- src/pakfire/job.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/pakfire/job.c b/src/pakfire/job.c index d5294687..dbf5ef49 100644 --- a/src/pakfire/job.c +++ b/src/pakfire/job.c @@ -753,9 +753,10 @@ int pakfire_job_launch(struct pakfire_job* job) { } static int pakfire_job_send_log_line(struct pakfire_job* job, - int priority, const char* line, size_t length) { + const struct timeval* timestamp, int priority, const char* line, size_t length) { struct json_object* message = NULL; struct json_object* data = NULL; + char buffer[64]; int r; // Create a new JSON object @@ -766,6 +767,16 @@ static int pakfire_job_send_log_line(struct pakfire_job* job, goto ERROR; } + // Format timestamp + r = pakfire_timeval_to_iso8601(buffer, timestamp); + if (r < 0) + goto ERROR; + + // Add the timestamp + r = pakfire_json_add_string(data, "timestamp", buffer); + if (r < 0) + goto ERROR; + // Add the priority r = pakfire_json_add_uint64(data, "priority", priority); if (r) @@ -836,7 +847,7 @@ static int pakfire_job_stream(sd_event_source* s, void* data) { break; // If we have received a line let's send it - r = pakfire_job_send_log_line(job, priority, line, length); + r = pakfire_job_send_log_line(job, ×tamp, priority, line, length); free(line); if (r < 0) return r; -- 2.39.5