vlib: add a "vpplog" debug CLI 27/31327/2
authorDave Barach <dave@barachs.net>
Wed, 17 Feb 2021 15:25:18 +0000 (10:25 -0500)
committerFlorin Coras <florin.coras@gmail.com>
Thu, 18 Feb 2021 15:42:03 +0000 (15:42 +0000)
To add arbitrary text to the vlib log. Combines nicely with
comment/uncomment and the macro expander:

define MY_FEATURE uncomment   # or comment
...
$(MY_FEATURE) { vpplog { My feature was enabled } }

Type: improvement

Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: Ia019f0a8fa670d8593ae01595f5ef410796e5b1c

src/vlib/cli.c
src/vlib/cli.h

index e1db95d..85ec6cb 100644 (file)
@@ -472,6 +472,23 @@ vlib_cli_dispatch_sub_commands (vlib_main_t * vm,
       vec_free (string);
     }
 
+  else if (unformat (input, "vpplog %v", &string))
+    {
+      int i;
+      /*
+       * Delete leading whitespace, so "vpplog { this and that }"
+       * and "vpplog this" line up nicely.
+       */
+      for (i = 0; i < vec_len (string); i++)
+       if (string[i] != ' ')
+         break;
+      if (i > 0)
+       vec_delete (string, i, 0);
+
+      vlib_log_notice (cm->log, "CLI: %v", string);
+      vec_free (string);
+    }
+
   else if (unformat (input, "uncomment %U",
                     unformat_vlib_cli_sub_input, &sub_input))
     {
@@ -1817,6 +1834,9 @@ vlib_cli_init (vlib_main_t * vm)
        return error;
       cmd = cmd->next_cli_command;
     }
+
+  cm->log = vlib_log_register_class_rate_limit (
+    "cli", "log", 0x7FFFFFFF /* aka no rate limit */);
   return error;
 }
 
index 0a8ef9d..c31236f 100644 (file)
@@ -41,6 +41,7 @@
 #define included_vlib_cli_h
 
 #include <vppinfra/format.h>
+#include <vlib/log.h>
 
 struct vlib_cli_command_t;
 
@@ -152,6 +153,10 @@ typedef struct vlib_cli_main_t
     (struct vlib_cli_main_t *, u32 id, int before_or_after);
   void (**perf_counter_cbs_tmp)
     (struct vlib_cli_main_t *, u32 id, int before_or_after);
+
+  /* cli log */
+  vlib_log_class_t log;
+
 } vlib_cli_main_t;
 
 #ifndef CLIB_MARCH_VARIANT