# define CTX_DEBUG pakfire_ctx_log_null
#endif
-// Below is the legacy logging mechanism
+#define PAKFIRE_INFO(pakfire, arg...) pakfire_log_condition(pakfire, LOG_INFO, ## arg)
+#define PAKFIRE_ERROR(pakfire, arg...) pakfire_log_condition(pakfire, LOG_ERR, ## arg)
-#ifdef PAKFIRE_LEGACY_LOGGING
+#define pakfire_log_condition(pakfire, level, arg...) \
+ do { \
+ if (pakfire_get_log_level(pakfire) >= level) \
+ pakfire_log(pakfire, level, __FILE__, __LINE__, __FUNCTION__, ## arg); \
+ } while (0)
// This function does absolutely nothing
static inline void __attribute__((always_inline, format(printf, 2, 3)))
- pakfire_log_null(struct pakfire* pakfire, const char *format, ...) {}
+ pakfire_log_null(struct pakfire_ctx* ctx, const char *format, ...) {}
+
+#ifdef ENABLE_DEBUG
+# define PAKFIRE_DEBUG(pakfire, arg...) pakfire_log_condition(pakfire, LOG_DEBUG, ## arg)
+#else
+# define PAKFIRE_DEBUG pakfire_log_null
+#endif
-#define pakfire_log_condition(pakfire, prio, r, arg...) \
- pakfire_log(pakfire, prio, r, __FILE__, __LINE__, __FUNCTION__, ## arg)
+// Below is the legacy logging mechanism
-#define INFO(pakfire, arg...) pakfire_log_condition(pakfire, LOG_INFO, 0, ## arg)
-#define ERROR(pakfire, arg...) pakfire_log_condition(pakfire, LOG_ERR, 0, ## arg)
+#ifdef PAKFIRE_LEGACY_LOGGING
-#define INFO_ERRNO(pakfire, r, arg...) pakfire_log_condition(pakfire, LOG_INFO, r, ## arg)
-#define ERROR_ERRNO(pakfire, r, arg...) pakfire_log_condition(pakfire, LOG_ERR, r, ## arg)
+#define INFO(pakfire, arg...) pakfire_log_condition(pakfire, LOG_INFO, ## arg)
+#define ERROR(pakfire, arg...) pakfire_log_condition(pakfire, LOG_ERR, ## arg)
#ifdef ENABLE_DEBUG
-# define DEBUG(pakfire, arg...) pakfire_log_condition(pakfire, LOG_DEBUG, 0, ## arg)
-# define DEBUG_ERRNO(pakfire, r, arg...) pakfire_log_condition(pakfire, LOG_DEBUG, r, ## arg)
+# define DEBUG(pakfire, arg...) pakfire_log_condition(pakfire, LOG_DEBUG, ## arg)
#else
# define DEBUG pakfire_log_null
-# define DEBUG_ERRNO pakfire_log_null
#endif
#endif /* PAKFIRE_LEGACY_LOGGING */
const struct pakfire_subid* pakfire_subuid(struct pakfire* pakfire);
const struct pakfire_subid* pakfire_subgid(struct pakfire* pakfire);
-void pakfire_log(struct pakfire* pakfire, int priority, int r, const char *file,
- int line, const char *fn, const char *format, ...)
- __attribute__((format(printf, 7, 8)));
+// Logging
+
+int pakfire_get_log_level(struct pakfire* pakfire);
+
+void pakfire_log(struct pakfire* pakfire, int level, const char* file, int line,
+ const char* fn, const char* format, ...) __attribute__((format(printf, 6, 7)));
// Locking
int pakfire_acquire_lock(struct pakfire* pakfire);
// Logging
-// XXX This function is deprecated and needs to be removed
-void pakfire_log(struct pakfire* pakfire, int priority, int r,
+int pakfire_get_log_level(struct pakfire* pakfire) {
+ return pakfire_ctx_get_log_level(pakfire->ctx);
+}
+
+void pakfire_log(struct pakfire* pakfire, int priority,
const char* file, int line, const char* fn, const char* format, ...) {
char* buffer = NULL;
va_list args;
-
- // Save errno
- int saved_errno = errno;
- if (r)
- errno = r;
+ int r;
va_start(args, format);
r = vasprintf(&buffer, format, args);
va_end(args);
- // Restore errno
- errno = saved_errno;
-
if (r < 0)
return;