return 0;
}
-static int log_callback(struct pakfire* pakfire, void* data,
- int priority, const char* message, size_t length) {
+static int 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;
+
+ // Format the 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;
+
switch (priority) {
+ // Highlight any error messages
case LOG_ERR:
- fprintf(stderr, "%s%.*s%s", color_highlight(), (int)length, message, color_reset());
+ fprintf(stderr, "%s%s%s", color_highlight(), buffer, color_reset());
break;
+ // Print the rest to stdout
default:
- fprintf(stdout, "%.*s", (int)length, message);
+ fprintf(stdout, "%s", buffer);
break;
}
+ // Cleanup
+ if (buffer)
+ free(buffer);
+
return 0;
}
"\n" \
"exit 0\n"
+/*
+ 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)
+
+#define BUILD_LOG_ERRNO(build, priority, r, arg...) \
+ pakfire_build_log(build, priority, r, __FILE__, __LINE__, __FUNCTION__, ## arg)
+#define BUILD_LOG(build, priority, arg...) BUILD_LOG_ERRNO(build, priority, 0, ## arg)
+
+#define BUILD_INFO_ERRNO(build, r, arg...) BUILD_LOG_ERRNO(build, LOG_INFO, r, ## arg)
+#define BUILD_ERROR_ERRNO(build, r, arg...) BUILD_LOG_ERRNO(build, LOG_ERR, r, ## arg)
+
+#define BUILD_INFO(build, arg...) BUILD_INFO_ERRNO(build, 0, ## arg)
+#define BUILD_ERROR(build, arg...) BUILD_ERROR_ERRNO(build, 0, ## arg)
+
static int pakfire_build_has_flag(struct pakfire_build* build, int flag) {
return build->flags & flag;
}
return r;
}
-static int pakfire_build_default_log_callback(struct pakfire* pakfire,
- void* data, int priority, const char* message, size_t length) {
- // Pass the message to the upstream logger
- pakfire_log_condition(pakfire, priority, 0, "%.*s", (int)length, message);
+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;
- return 0;
-}
+ // Only pass messages to the pakfire logger that are wanted
+ if (pakfire_log_get_priority(build->pakfire) < priority)
+ return 0;
-static int pakfire_build_log_prepend_timestamp(
- char** buffer, const double t, const char* message, const int l) {
- const unsigned int h = (unsigned int)t / 3600;
- const unsigned int m = (unsigned int)t % 3600 / 60;
- const unsigned int s = (unsigned int)t % 60;
- const unsigned int ms = (unsigned int)(t * 1000.0) % 1000;
+ // Format the message
+ va_start(args, format);
+ r = vasprintf(&buffer, format, args);
+ va_end(args);
- if (h)
- return asprintf(buffer, "[%02d:%02d:%02d.%04d] %.*s", h, m, s, ms, l, message);
+ // Fail if we could not format the string
+ if (r < 0)
+ return r;
- else if (m)
- return asprintf(buffer, "[ %02d:%02d.%04d] %.*s", m, s, ms, l, message);
+ // Send the message to the upstream logger
+ pakfire_log(build->pakfire, priority, error, file, line, function, "%s", buffer);
- else
- return asprintf(buffer, "[ %02d.%04d] %.*s", s, ms, l, message);
+ // 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;
- char* buffer = NULL;
- int r;
// Get the runtime of the build
const double t = pakfire_build_duration(build);
if (t < 0)
return t;
- // Format the timestamp
- r = pakfire_build_log_prepend_timestamp(&buffer, t, line, length);
- if (r < 0)
- return r;
+ const unsigned int h = (unsigned int)t / 3600;
+ const unsigned int m = (unsigned int)t % 3600 / 60;
+ const unsigned int s = (unsigned int)t % 60;
+ const unsigned int ms = (unsigned int)(t * 1000.0) % 1000;
- // Run the log callback
- r = build->callbacks.log(pakfire, build->callbacks.log_data, priority, buffer, r);
+ if (h)
+ return BUILD_LOG(build, priority, "[%02d:%02d:%02d.%04d] %.*s", h, m, s, ms, length, line);
- // Cleanup
- if (buffer)
- free(buffer);
+ else if (m)
+ return BUILD_LOG(build, priority, "[ %02d:%02d.%04d] %.*s", m, s, ms, length, line);
- return r;
+ else
+ return BUILD_LOG(build, priority, "[ %02d.%04d] %.*s", s, ms, length, line);
}
/*
const char* nevra = pakfire_package_get_string(package, PAKFIRE_PKG_NEVRA);
- INFO(build->pakfire, "Building %s...\n", nevra);
+ BUILD_INFO(build, "Building %s...\n", nevra);
// Check if this package can be build in this environment
if (!pakfire_package_supports_build_arch(package, arch)) {