+/**
+ * Set the libsigrok log callback to the specified function.
+ *
+ * @param cb Function pointer to the log callback function to use.
+ * Must not be NULL.
+ * @param cb_data Pointer to private data to be passed on. This can be used by
+ * the caller to pass arbitrary data to the log functions. This
+ * pointer is only stored or passed on by libsigrok, and is
+ * never used or interpreted in any way. The pointer is allowed
+ * to be NULL if the caller doesn't need/want to pass any data.
+ *
+ * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments.
+ *
+ * @since 0.3.0
+ */
+SR_API int sr_log_callback_set(sr_log_callback cb, void *cb_data)
+{
+ if (!cb) {
+ sr_err("log: %s: cb was NULL", __func__);
+ return SR_ERR_ARG;
+ }
+
+ /* Note: 'cb_data' is allowed to be NULL. */
+
+ sr_log_cb = cb;
+ sr_log_cb_data = cb_data;
+
+ return SR_OK;
+}
+
+/**
+ * Set the libsigrok log callback to the default built-in one.
+ *
+ * Additionally, the internal 'sr_log_cb_data' pointer is set to NULL.
+ *
+ * @return SR_OK upon success, a negative error code otherwise.
+ *
+ * @since 0.1.0
+ */
+SR_API int sr_log_callback_set_default(void)
+{
+ /*
+ * Note: No log output in this function, as it should safely work
+ * even if the currently set log callback is buggy/broken.
+ */
+ sr_log_cb = sr_logv;
+ sr_log_cb_data = NULL;
+
+ return SR_OK;
+}
+
+static int sr_logv(void *cb_data, int loglevel, const char *format, va_list args)