misc: pass NULL instead of 0 for pointer in variadic functions
[vpp.git] / src / vlib / log.c
index e1ab036..d084511 100644 (file)
 #include <vlib/log.h>
 #include <vlib/unix/unix.h>
 #include <syslog.h>
+#include <vppinfra/elog.h>
 
 vlib_log_main_t log_main = {
   .default_log_level = VLIB_LOG_LEVEL_NOTICE,
   .default_syslog_log_level = VLIB_LOG_LEVEL_WARNING,
   .unthrottle_time = 3,
   .size = 512,
+  .add_to_elog = 1,
   .default_rate_limit = 50,
 };
 
@@ -222,6 +224,37 @@ vlib_log (vlib_log_level_t level, vlib_log_class_t class, char *fmt, ...)
       e->timestamp = t;
       s = 0;
 
+      if (lm->add_to_elog)
+       {
+          /* *INDENT-OFF* */
+          ELOG_TYPE_DECLARE(ee) =
+            {
+             .format = "log-%s: %s",
+             .format_args = "t4T4",
+             .n_enum_strings = 9,
+             .enum_strings = {
+                "emerg",
+                "alert",
+                "crit",
+                "err",
+                "warn",
+                "notice",
+                "info",
+                "debug",
+                "disabled",
+                },
+            };
+          struct {
+            u32 log_level;
+            u32 string_index;
+          } *ed;
+          /* *INDENT-ON* */
+         ed = ELOG_DATA (&vlib_global_main.elog_main, ee);
+         ed->log_level = level;
+         ed->string_index =
+           elog_string (&vlib_global_main.elog_main, "%v%c", e->string, 0);
+       }
+
       lm->next = (lm->next + 1) % lm->size;
       if (lm->size > lm->count)
        lm->count++;
@@ -333,8 +366,8 @@ format_vlib_log_level (u8 * s, va_list * args)
   return format (s, "%s", t);
 }
 
-static clib_error_t *
-vlib_log_init (vlib_main_t * vm)
+clib_error_t *
+vlib_log_init (vlib_main_t *vm)
 {
   vlib_log_main_t *lm = &log_main;
   vlib_log_class_registration_t *r = lm->registrations;
@@ -363,9 +396,6 @@ vlib_log_init (vlib_main_t * vm)
   return 0;
 }
 
-VLIB_INIT_FUNCTION (vlib_log_init);
-
-
 static clib_error_t *
 show_log (vlib_main_t * vm,
          unformat_input_t * input, vlib_cli_command_t * cmd)
@@ -383,10 +413,9 @@ show_log (vlib_main_t * vm,
   while (count--)
     {
       e = vec_elt_at_index (lm->entries, i);
-      vlib_cli_output (vm, "%U %-10U %-14U %v",
-                      format_time_float, 0, e->timestamp + time_offset,
-                      format_vlib_log_level, e->level,
-                      format_vlib_log_class, e->class, e->string);
+      vlib_cli_output (vm, "%U %-10U %-14U %v", format_time_float, NULL,
+                      e->timestamp + time_offset, format_vlib_log_level,
+                      e->level, format_vlib_log_class, e->class, e->string);
       i = (i + 1) % lm->size;
     }
 
@@ -822,6 +851,8 @@ log_config (vlib_main_t * vm, unformat_input_t * input)
                         unformat_vlib_log_level,
                         &lm->default_syslog_log_level))
        ;
+      else if (unformat (input, "add-to-elog"))
+       lm->add_to_elog = 1;
       else if (unformat (input, "class %s %U", &class,
                         unformat_vlib_cli_sub_input, &sub_input))
        {