]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: add "log error-code" switch 3123/head
authorDavid Lamparter <equinox@opensourcerouting.org>
Tue, 2 Oct 2018 22:19:11 +0000 (00:19 +0200)
committerDavid Lamparter <equinox@opensourcerouting.org>
Wed, 3 Oct 2018 21:24:24 +0000 (23:24 +0200)
Signed-off-by: David Lamparter <equinox@diac24.net>
lib/command.c
lib/log.c
lib/log.h
lib/log_int.h

index 1df644210723a3e7ec47ad382bf79940d08c5d82..850980bd4e3fee38a9d1ffad0d611c1192bd4f77 100644 (file)
@@ -570,6 +570,9 @@ static int config_write_host(struct vty *vty)
                if (zlog_default->record_priority == 1)
                        vty_out(vty, "log record-priority\n");
 
+               if (zlog_default->error_code)
+                       vty_out(vty, "log error-code\n");
+
                if (zlog_default->timestamp_precision > 0)
                        vty_out(vty, "log timestamp precision %d\n",
                                zlog_default->timestamp_precision);
@@ -2334,6 +2337,8 @@ DEFUN (show_logging,
        vty_out(vty, "Protocol name: %s\n", zl->protoname);
        vty_out(vty, "Record priority: %s\n",
                (zl->record_priority ? "enabled" : "disabled"));
+       vty_out(vty, "Error code: %s\n",
+               (zl->error_code ? "enabled" : "disabled"));
        vty_out(vty, "Timestamp precision: %d\n", zl->timestamp_precision);
 
        return CMD_SUCCESS;
@@ -2612,6 +2617,17 @@ DEFUN (no_config_log_record_priority,
        return CMD_SUCCESS;
 }
 
+DEFUN (config_log_error_code,
+       config_log_error_code_cmd,
+       "[no] log error-code",
+       NO_STR
+       "Logging control\n"
+       "Log the error code number where available\n")
+{
+       zlog_default->error_code = !!strcmp(argv[0]->text, "no");
+       return CMD_SUCCESS;
+}
+
 DEFUN (config_log_timestamp_precision,
        config_log_timestamp_precision_cmd,
        "log timestamp precision (0-6)",
@@ -2883,6 +2899,7 @@ void cmd_init(int terminal)
                install_element(CONFIG_NODE, &config_log_record_priority_cmd);
                install_element(CONFIG_NODE,
                                &no_config_log_record_priority_cmd);
+               install_element(CONFIG_NODE, &config_log_error_code_cmd);
                install_element(CONFIG_NODE,
                                &config_log_timestamp_precision_cmd);
                install_element(CONFIG_NODE,
index b067018e08de3bdef4b33f9b2b635a3fc0b3833f..5f0bbff2a204b737d0103ecbc67787e5a9044a04 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -684,6 +684,23 @@ ZLOG_FUNC(zlog_debug, LOG_DEBUG)
 
 #undef ZLOG_FUNC
 
+void zlog_err_id(uint32_t id, const char *format, ...)
+{
+       va_list args;
+       va_start(args, format);
+       if (zlog_default && zlog_default->error_code) {
+               char newfmt[strlen(format) + 32];
+
+               snprintf(newfmt, sizeof(newfmt), "[EC %"PRIu32"] %s", id,
+                        format);
+               vzlog(LOG_ERR, newfmt, args);
+       } else {
+               vzlog(LOG_ERR, format, args);
+       }
+       va_end(args);
+}
+
+
 void zlog_thread_info(int log_level)
 {
        struct thread *tc;
index 7d05b846411ea3d38cfefeb0d1f49cd35af92bfe..7b21a0ce37716475490a8e295eca50c9fa1baaa6 100644 (file)
--- a/lib/log.h
+++ b/lib/log.h
@@ -79,6 +79,8 @@ extern void closezlog(void);
 #endif /* __GNUC__ */
 
 /* Handy zlog functions. */
+extern void zlog_err_id(uint32_t id, const char *format, ...)
+       PRINTF_ATTRIBUTE(2, 3);
 extern void zlog_err(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
 extern void zlog_warn(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
 extern void zlog_info(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
@@ -87,7 +89,7 @@ extern void zlog_debug(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
 
 /* For logs which have error codes associated with them */
 #define flog_err(ferr_id, format, ...)                                        \
-       zlog_err("[EC %"PRIu32"] " format, ferr_id, ##__VA_ARGS__)
+       zlog_err_id(ferr_id, format, ##__VA_ARGS__)
 #define flog_err_sys(ferr_id, format, ...)                                     \
        flog_err(ferr_id, format, ##__VA_ARGS__)
 
index a7f8be9ae71499eb6c67eee2d61091b25e7d6824..e17d0e80d2bbddf09bc3220ff8fc7b8203241eb5 100644 (file)
@@ -36,6 +36,7 @@ struct zlog {
        int facility;   /* as per syslog facility */
        int record_priority; /* should messages logged through stdio include the
                                priority of the message? */
+       int error_code;
        int syslog_options;  /* 2nd arg to openlog */
        int timestamp_precision; /* # of digits of subsecond precision */
 };