#include <ctype.h>
#include <errno.h>
+#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
ctx->log.callback = callback;
ctx->log.data = data;
}
+
+void pakfire_ctx_log(struct pakfire_ctx* ctx, int level, const char* file, int line,
+ const char* fn, const char* format, ...) {
+ va_list args;
+
+ // Return if the callback hasn't been set
+ if (!ctx->log.callback)
+ return;
+
+ va_start(args, format);
+ ctx->log.callback(ctx->log.data, level, file, line, fn, format, args);
+ va_end(args);
+}
void pakfire_ctx_set_log_callback(struct pakfire_ctx* ctx,
pakfire_log_callback callback, void* data);
+#ifdef PAKFIRE_PRIVATE
+
+void pakfire_ctx_log(struct pakfire_ctx* ctx, int level, const char* file, int line,
+ const char* fn, const char* format, ...) __attribute__((format(printf, 6, 7)));
+
+#endif /* PAKFIRE_PRIVATE */
+
#endif /* PAKFIRE_CTX_H */
#ifdef PAKFIRE_PRIVATE
+#include <pakfire/ctx.h>
+
+#define pakfire_ctx_log_condition(ctx, level, r, arg...) \
+ do { \
+ if (pakfire_ctx_get_log_level(pakfire) >= level) \
+ pakfire_ctx_log(ctx, level, r, __FILE__, __LINE__, __FUNCTION__, ## arg); \
+ } while (0)
+
+// This function does absolutely nothing
+static inline void __attribute__((always_inline, format(printf, 2, 3)))
+ pakfire_ctx_log_null(struct pakfire_ctx* ctx, const char *format, ...) {}
+
+#define CTX_INFO(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_INFO, 0, ## arg)
+#define CTX_ERROR(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_ERR, 0, ## arg)
+
+#ifdef ENABLE_DEBUG
+# define CTX_DEBUG(ctx, arg...) pakfire_ctx_log_condition(ctx, LOG_DEBUG, 0, ## arg)
+#else
+# define CTX_DEBUG pakfire_ctx_log_null
+#endif
+
+// Below is the legacy logging mechanism
+
// This function does absolutely nothing
static inline void __attribute__((always_inline, format(printf, 2, 3)))
pakfire_log_null(struct pakfire* pakfire, const char *format, ...) {}