]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: introduce flog() to simplify the northbound code a little bit
authorRenato Westphal <renato@opensourcerouting.org>
Mon, 15 Apr 2019 22:03:57 +0000 (19:03 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Thu, 18 Apr 2019 16:17:54 +0000 (13:17 -0300)
flog() is a small wrapper around zlog() that can be useful in a
few places to reduce code duplication.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/log.h
lib/northbound.c

index 09d3a65ecda9f0933fb71f4fcfd19b2b836f78ee..9368bf9e829937fda784740a036e86450325d4b8 100644 (file)
--- a/lib/log.h
+++ b/lib/log.h
@@ -103,7 +103,8 @@ extern void zlog(int priority, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
        flog_err(ferr_id, format, ##__VA_ARGS__)
 #define flog_warn(ferr_id, format, ...)                                        \
        zlog_warn("[EC %" PRIu32 "] " format, ferr_id, ##__VA_ARGS__)
-
+#define flog(priority, ferr_id, format, ...)                                   \
+       zlog(priority, "[EC %" PRIu32 "] " format, ferr_id, ##__VA_ARGS__)
 
 extern void zlog_thread_info(int log_level);
 
index fd92aaa9d356edd487ded567ab3de79cddfe8af5..83c056957bcaa9431049d022de0a9649f7f4a5c0 100644 (file)
@@ -753,40 +753,44 @@ static int nb_callback_configuration(const enum nb_event event,
                ret = (*nb_node->cbs.move)(event, dnode);
                break;
        default:
-               break;
+               flog_err(EC_LIB_DEVELOPMENT,
+                        "%s: unknown operation (%u) [xpath %s]", __func__,
+                        operation, xpath);
+               exit(1);
        }
 
        if (ret != NB_OK) {
-               enum lib_log_refs ref = 0;
+               int priority;
+               enum lib_log_refs ref;
 
                switch (event) {
                case NB_EV_VALIDATE:
+                       priority = LOG_WARNING;
                        ref = EC_LIB_NB_CB_CONFIG_VALIDATE;
                        break;
                case NB_EV_PREPARE:
+                       priority = LOG_WARNING;
                        ref = EC_LIB_NB_CB_CONFIG_PREPARE;
                        break;
                case NB_EV_ABORT:
+                       priority = LOG_WARNING;
                        ref = EC_LIB_NB_CB_CONFIG_ABORT;
                        break;
                case NB_EV_APPLY:
+                       priority = LOG_ERR;
                        ref = EC_LIB_NB_CB_CONFIG_APPLY;
                        break;
+               default:
+                       flog_err(EC_LIB_DEVELOPMENT,
+                                "%s: unknown event (%u) [xpath %s]",
+                                __func__, event, xpath);
+                       exit(1);
                }
-               if (event == NB_EV_VALIDATE || event == NB_EV_PREPARE)
-                       flog_warn(
-                               ref,
-                               "%s: error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]",
-                               __func__, nb_err_name(ret),
-                               nb_event_name(event),
-                               nb_operation_name(operation), xpath);
-               else
-                       flog_err(
-                               ref,
-                               "%s: error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]",
-                               __func__, nb_err_name(ret),
-                               nb_event_name(event),
-                               nb_operation_name(operation), xpath);
+
+               flog(priority, ref,
+                    "%s: error processing configuration change: error [%s] event [%s] operation [%s] xpath [%s]",
+                    __func__, nb_err_name(ret), nb_event_name(event),
+                    nb_operation_name(operation), xpath);
        }
 
        return ret;