log FEATURE specific model error-app-tag set and provided to user
diff --git a/src/common.c b/src/common.c
index c54ea95..dc9fc53 100644
--- a/src/common.c
+++ b/src/common.c
@@ -138,6 +138,18 @@
return &e->path[e->path_index];
}
+API const char *
+ly_errapptag(void)
+{
+ struct ly_err *e;
+
+ e = ly_err_location();
+ if (!e) {
+ return NULL;
+ }
+ return e->apptag;
+}
+
uint8_t *
ly_vlog_hide_location(void)
{
diff --git a/src/common.h b/src/common.h
index a9f77b6..376e109 100644
--- a/src/common.h
+++ b/src/common.h
@@ -61,6 +61,7 @@
#endif
#define LY_BUF_SIZE 1024
+#define LY_APPTAG_LEN 128
struct ly_err {
LY_ERR no;
LY_VECODE code;
@@ -70,6 +71,7 @@
const void *path_obj;
char msg[LY_BUF_SIZE];
char path[LY_BUF_SIZE];
+ char apptag[LY_APPTAG_LEN];
char buf[LY_BUF_SIZE];
};
diff --git a/src/libyang.h b/src/libyang.h
index 3c9af53..697c5a2 100644
--- a/src/libyang.h
+++ b/src/libyang.h
@@ -924,6 +924,11 @@
/**
* @brief Set 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] 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,
@@ -1052,7 +1057,8 @@
#define ly_vecode (*ly_vecode_location())
/**
- * @brief Get the last (thread-specific) error message.
+ * @brief Get the last (thread-specific) error message. If the coresponding module defined
+ * a specific error message, it will be used instead the default one.
*
* Sometimes, the error message is extended with path of the element where is the problem.
* The path is available via ly_errpath().
@@ -1071,6 +1077,17 @@
*/
const char *ly_errpath(void);
+/**
+ * @brief Get the last (thread-specific) error-app-tag if there was a specific one defined
+ * in the module for the last error.
+ *
+ * The app-tag always corresponds to the error message available via ly_errmsg(), so
+ * whenever a subsequent error message is printed, the app-tag is erased or rewritten.
+ *
+ * @return Error-app-tag of the last error.
+ */
+const char *ly_errapptag(void);
+
/**@} logger */
#ifdef __cplusplus
diff --git a/src/log.c b/src/log.c
index e83272f..60bd9a7 100644
--- a/src/log.c
+++ b/src/log.c
@@ -79,10 +79,15 @@
msg[LY_BUF_SIZE - 1] = '\0';
}
- if (level == LY_LLERR && !path) {
- /* erase previous path */
- ((struct ly_err *)&ly_errno)->path_index = LY_BUF_SIZE - 1;
- ((struct ly_err *)&ly_errno)->path_obj = NULL;
+ if (level == LY_LLERR) {
+ if (!path) {
+ /* erase previous path */
+ ((struct ly_err *)&ly_errno)->path_index = LY_BUF_SIZE - 1;
+ ((struct ly_err *)&ly_errno)->path_obj = NULL;
+ }
+
+ /* if the error-app-tag should be set, do it after calling LOGVAL */
+ ((struct ly_err *)&ly_errno)->apptag[0] = '\0';
}
if (hide) {