]> git.ipfire.org Git - pakfire.git/commitdiff
build: Implement custom logging that shows build time
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 31 Aug 2023 04:18:05 +0000 (04:18 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 31 Aug 2023 04:18:05 +0000 (04:18 +0000)
Fixes: #13250 - log: Add timestamp for each log line
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index a6c71ed0ca0562e0384fb17dc1131c84153425d5..194a8a638cb9888b6f3230a54ee5764920cfd392 100644 (file)
@@ -1393,6 +1393,28 @@ ERROR:
        return r;
 }
 
+static int pakfire_build_log_callback(struct pakfire* pakfire,
+               void* data, int priority, const char* line, size_t length) {
+       struct pakfire_build* build = data;
+       char buffer[128];
+       int r;
+
+       // Get the runtime of the build
+       const time_t t = pakfire_build_duration(build);
+       if (t < 0)
+               return t;
+
+       // Format the timestamp
+       r = pakfire_string_format(buffer, "%8ld", t);
+       if (r < 0)
+               return r;
+
+       // Pass the message to the upstream logger
+       pakfire_log_condition(pakfire, priority, 0, "[%s] %s", buffer, line);
+
+       return 0;
+}
+
 /*
        Sets up a new jail for this build
 */
@@ -1406,6 +1428,9 @@ static int pakfire_build_setup_jail(struct pakfire_build* build) {
                return r;
        }
 
+       // Configure our custom logging callback
+       pakfire_jail_set_log_callback(build->jail, pakfire_build_log_callback, build);
+
        // Connect the jail to our cgroup
        r = pakfire_jail_set_cgroup(build->jail, build->cgroup);
        if (r) {