+/**
+ * Set the libsigrokdecode 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 libsigrokdecode,
+ * 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 SRD_OK upon success, SRD_ERR_ARG upon invalid arguments.
+ *
+ * @since 0.3.0
+ */
+SRD_API int srd_log_callback_set(srd_log_callback cb, void *cb_data)
+{
+ if (!cb) {
+ srd_err("log: %s: cb was NULL", __func__);
+ return SRD_ERR_ARG;
+ }
+
+ /* Note: 'cb_data' is allowed to be NULL. */
+
+ srd_log_cb = cb;
+ srd_log_cb_data = cb_data;
+
+ return SRD_OK;
+}
+
+/**
+ * Set the libsigrokdecode log callback to the default built-in one.
+ *
+ * Additionally, the internal 'srd_log_cb_data' pointer is set to NULL.
+ *
+ * @return SRD_OK upon success, a (negative) error code otherwise.
+ *
+ * @since 0.1.0
+ */
+SRD_API int srd_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.
+ */
+ srd_log_cb = srd_logv;
+ srd_log_cb_data = NULL;
+
+ return SRD_OK;
+}
+
+static int srd_logv(void *cb_data, int loglevel, const char *format,
+ va_list args)