#include <stdlib.h>
#include <stdbool.h>
+#include <stdarg.h>
#include <sys/types.h>
typedef enum zck_hash {
/* Clear error message
* Returns 1 if message was cleared, 0 if error is fatal and can't be cleared */
bool zck_clear_error(zckCtx *zck);
+/* Set a callback for logs instead to write into a fd */
+typedef void (*logcallback)(const char *function, zck_log_type lt, const char *format, va_list args);
+void zck_set_log_callback(logcallback function);
/*******************************************************************
* Miscellaneous utilities
static zck_log_type log_level = ZCK_LOG_ERROR;
static int log_fd = STDERR_FILENO;
+static logcallback callback = NULL;
+
void PUBLIC zck_set_log_level(zck_log_type ll) {
log_level = ll;
}
log_fd = fd;
}
+void PUBLIC zck_set_log_callback(logcallback function) {
+ if (!function)
+ return;
+ callback = function;
+}
+
void zck_log_v(const char *function, zck_log_type lt, const char *format,
va_list args) {
if(lt < log_level || log_level == ZCK_LOG_ERROR)
return;
- dprintf(log_fd, "%s: ", function);
- vdprintf(log_fd, format, args);
- dprintf(log_fd, "\n");
+ if (callback) {
+ callback(function, lt, format, args);
+ } else {
+ dprintf(log_fd, "%s: ", function);
+ vdprintf(log_fd, format, args);
+ dprintf(log_fd, "\n");
+ }
}
void zck_log_wf(const char *function, zck_log_type lt, const char *format, ...) {