lib: introduce flog() to simplify the northbound code a little bit

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>
This commit is contained in:
Renato Westphal 2019-04-15 19:03:57 -03:00
parent e412d3b8d9
commit c650e48c54
2 changed files with 22 additions and 17 deletions

View File

@ -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);

View 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;