]> git.ipfire.org Git - pakfire.git/commitdiff
build: Always send everything to the parent logger, too
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Sep 2023 12:00:36 +0000 (12:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 30 Sep 2023 12:00:36 +0000 (12:00 +0000)
This patch will make sure that we log everything to the parent logger,
too.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/build.c

index 2696554776a17c9205a0bb4a4ff8f0253ef74ee6..b53c1a043115e4bad7aaad07165f72ee795fa41f 100644 (file)
@@ -122,9 +122,41 @@ struct pakfire_build {
 /*
        Convenience macro to call the logger callback
 */
-#define pakfire_build_log(build, priority, r, file, line, function, format, arg...) \
-       build->callbacks.log(build, build->callbacks.log_data, \
-                       priority, r, file, line, function, format, ## arg)
+static int pakfire_build_log(struct pakfire_build* build, int priority, int error,
+               const char* file, int line, const char* function, const char* format, ...) {
+       char* buffer = NULL;
+       va_list args;
+       int r;
+
+       // Don't log messages of a lower loglevel
+       if (pakfire_log_get_priority(build->pakfire) < priority)
+               return 0;
+
+       // Format message
+       va_start(args, format);
+       r = vasprintf(&buffer, format, args);
+       va_end(args);
+
+       // Fail if we could not format the message
+       if (r < 0)
+               return r;
+
+       // Send everything to the parent logger
+       pakfire_log(build->pakfire, priority, error, file, line, function, "%s", buffer);
+
+       // Call the build logger callback
+       if (build->callbacks.log)
+               r = build->callbacks.log(build, build->callbacks.log_data, priority, error,
+                       file, line, function, "%s", buffer);
+       else
+               r = 0;
+
+       // Cleanup
+       if (buffer)
+               free(buffer);
+
+       return r;
+}
 
 #define BUILD_LOG_ERRNO(build, priority, r, arg...) \
        pakfire_build_log(build, priority, r, __FILE__, __LINE__, __FUNCTION__, ## arg)
@@ -1422,35 +1454,6 @@ ERROR:
        return r;
 }
 
-static int pakfire_build_default_log_callback(struct pakfire_build* build, void* data,
-               int priority, int error, const char* file, int line, const char* function, const char* format, ...) {
-       char* buffer = NULL;
-       va_list args;
-       int r;
-
-       // Only pass messages to the pakfire logger that are wanted
-       if (pakfire_log_get_priority(build->pakfire) < priority)
-               return 0;
-
-       // Format the message
-       va_start(args, format);
-       r = vasprintf(&buffer, format, args);
-       va_end(args);
-
-       // Fail if we could not format the string
-       if (r < 0)
-               return r;
-
-       // Send the message to the upstream logger
-       pakfire_log(build->pakfire, priority, error, file, line, function, "%s", buffer);
-
-       // Cleanup
-       if (buffer)
-               free(buffer);
-
-       return 0;
-}
-
 static int pakfire_build_jail_log_callback(struct pakfire* pakfire,
                void* data, int priority, const char* line, size_t length) {
        struct pakfire_build* build = data;
@@ -1636,9 +1639,6 @@ PAKFIRE_EXPORT int pakfire_build_create(struct pakfire_build** build,
        // Copy flags
        b->flags = flags;
 
-       // Set default log callback
-       b->callbacks.log = pakfire_build_default_log_callback;
-
        // Store start time
        r = pakfire_build_set_time_start(b);
        if (r)