log REFACTOR typedef for logging callback
diff --git a/src/log.c b/src/log.c
index 9e470d2..3ae4f70 100644
--- a/src/log.c
+++ b/src/log.c
@@ -33,7 +33,7 @@
volatile uint8_t ly_log_level = LY_LLWRN;
volatile uint8_t ly_log_opts = LY_LOLOG | LY_LOSTORE_LAST;
-static void (*ly_log_clb)(LY_LOG_LEVEL level, const char *msg, const char *path);
+static ly_log_clb log_clb;
static volatile int path_flag = 1;
#ifndef NDEBUG
volatile int ly_log_dbg_groups = 0;
@@ -210,16 +210,16 @@
}
API void
-ly_set_log_clb(void (*clb)(LY_LOG_LEVEL level, const char *msg, const char *path), int path)
+ly_set_log_clb(ly_log_clb clb, int path)
{
- ly_log_clb = clb;
+ log_clb = clb;
path_flag = path;
}
-API void
-(*ly_get_log_clb(void))(LY_LOG_LEVEL, const char *, const char *)
+API ly_log_clb
+ly_get_log_clb(void)
{
- return ly_log_clb;
+ return log_clb;
}
static LY_ERR
@@ -330,8 +330,8 @@
/* if we are only storing errors internally, never print the message (yet) */
if (ly_log_opts & LY_LOLOG) {
- if (ly_log_clb) {
- ly_log_clb(level, msg, path);
+ if (log_clb) {
+ log_clb(level, msg, path);
} else {
fprintf(stderr, "libyang[%d]: %s%s", level, msg, path ? " " : "\n");
if (path) {
@@ -490,8 +490,8 @@
ly_err_print(struct ly_err_item *eitem)
{
if (ly_log_opts & LY_LOLOG) {
- if (ly_log_clb) {
- ly_log_clb(eitem->level, eitem->msg, eitem->path);
+ if (log_clb) {
+ log_clb(eitem->level, eitem->msg, eitem->path);
} else {
fprintf(stderr, "libyang[%d]: %s%s", eitem->level, eitem->msg, eitem->path ? " " : "\n");
if (eitem->path) {
diff --git a/src/log.h b/src/log.h
index 9176a04..87bab61 100644
--- a/src/log.h
+++ b/src/log.h
@@ -107,12 +107,21 @@
#endif
/**
- * @brief Set logger callback.
+ * @brief Logger callback.
*
* !IMPORTANT! If an error has a specific error-app-tag defined in the model, it will NOT be set
* at the time of calling this callback. It will be set right after, so to retrieve it
* it must be checked afterwards with ly_errapptag().
*
+ * @param[in] level Log level of the message.
+ * @param[in] msg Message.
+ * @param[in] path Optional path of the concerned node.
+ */
+typedef void (*ly_log_clb)(LY_LOG_LEVEL level, const char *msg, const char *path);
+
+/**
+ * @brief Set logger callback.
+ *
* @param[in] clb Logging callback.
* @param[in] path flag to resolve and provide path as the third parameter of the callback function. In case of
* validation and some other errors, it can be useful to get the path to the problematic element. Note,
@@ -120,13 +129,13 @@
* presence) or it can be NULL, so consider it as an optional parameter. If the flag is 0, libyang will
* not bother with resolving the path.
*/
-void ly_set_log_clb(void(*clb)(LY_LOG_LEVEL level, const char *msg, const char *path), int path);
+void ly_set_log_clb(ly_log_clb clb, int path);
/**
* @brief Get logger callback.
* @return Logger callback (can be NULL).
*/
-void (*ly_get_log_clb(void))(LY_LOG_LEVEL, const char *, const char *);
+ly_log_clb ly_get_log_clb(void);
/** @} log */