]> git.ipfire.org Git - pakfire.git/commitdiff
job: Send timestamp when streaming the log
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 7 Feb 2025 11:40:45 +0000 (11:40 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 7 Feb 2025 11:40:45 +0000 (11:40 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/job.c

index d52946870d916ef1352f27c008f4eae7aee17f5a..dbf5ef490dd638afedca0ff80c1e5f99f9111383 100644 (file)
@@ -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, &timestamp, priority, line, length);
                free(line);
                if (r < 0)
                        return r;