[ovs-dev] [PATCH 2/2] vlog: add "vlog/list PATTERN" command

Ansis Atteka aatteka at nicira.com
Wed Jun 17 07:53:54 UTC 2015


While it is possible to change PATTERN (a.k.a. logging format) for
destinations with vlog/set command, it is currently not possible to
retrieve logging format from a running daemon to verify its correctness.

This patch addresses this shortcomming by introducing "vlog/list PATTERN"
command.  Also, this command, for example, makes it obvious to user that,
if one uses libc syslog() call to log messages, then libc syslog() call
would add extra prefix to every log message that Open vSwitch sends to
syslog server.

Signed-Off-By: Ansis Atteka <aatteka at nicira.com>
---
 NEWS                       |  2 ++
 include/openvswitch/vlog.h |  1 +
 lib/vlog-unixctl.man       |  3 +++
 lib/vlog.c                 | 42 +++++++++++++++++++++++++++++++++++++-----
 utilities/ovs-appctl.8.in  |  5 +++--
 utilities/ovs-appctl.c     |  4 +++-
 6 files changed, 49 insertions(+), 8 deletions(-)

diff --git a/NEWS b/NEWS
index 9133e71..a324e85 100644
--- a/NEWS
+++ b/NEWS
@@ -106,6 +106,8 @@ Post-v2.3.0
    - Support for STT tunneling.
    - Support to configure method (--syslog-method argument) that determines
      how daemons will talk with syslog.
+   - Support for "ovs-appctl vlog/list PATTERN" command that lets to query
+     syslog message format for each destination.
 
 
 v2.3.0 - 14 Aug 2014
diff --git a/include/openvswitch/vlog.h b/include/openvswitch/vlog.h
index f2fedae..f6bb3ab 100644
--- a/include/openvswitch/vlog.h
+++ b/include/openvswitch/vlog.h
@@ -133,6 +133,7 @@ void vlog_set_levels(struct vlog_module *,
 char *vlog_set_levels_from_string(const char *) OVS_WARN_UNUSED_RESULT;
 void vlog_set_levels_from_string_assert(const char *);
 char *vlog_get_levels(void);
+char *vlog_get_patterns(void);
 bool vlog_is_enabled(const struct vlog_module *, enum vlog_level);
 bool vlog_should_drop(const struct vlog_module *, enum vlog_level,
                       struct vlog_rate_limit *);
diff --git a/lib/vlog-unixctl.man b/lib/vlog-unixctl.man
index 85dd11d..cf6a85b 100644
--- a/lib/vlog-unixctl.man
+++ b/lib/vlog-unixctl.man
@@ -51,6 +51,9 @@ Sets the log pattern for \fIdestination\fR to \fIpattern\fR.  Refer to
 .IP "\fBvlog/list\fR"
 Lists the supported logging modules and their current levels.
 .
+.IP "\fBvlog/list PATTERN\fR"
+Lists logging patterns used for each destination.
+.
 .IP "\fBvlog/reopen\fR"
 Causes \fB\*(PN\fR to close and reopen its log file.  (This is useful
 after rotating log files, to cause a new log file to be used.)
diff --git a/lib/vlog.c b/lib/vlog.c
index eca4482..fce1c43 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -606,10 +606,16 @@ vlog_unixctl_set(struct unixctl_conn *conn, int argc, const char *argv[],
 }
 
 static void
-vlog_unixctl_list(struct unixctl_conn *conn, int argc OVS_UNUSED,
-                  const char *argv[] OVS_UNUSED, void *aux OVS_UNUSED)
+vlog_unixctl_list(struct unixctl_conn *conn, int argc, const char *argv[],
+                  void *aux OVS_UNUSED)
 {
-    char *msg = vlog_get_levels();
+    char *msg;
+
+    if (argc > 1 && !strcasecmp("PATTERN", argv[1])) {
+        msg = vlog_get_patterns();
+    } else {
+        msg = vlog_get_levels();
+    }
     unixctl_command_reply(conn, msg);
     free(msg);
 }
@@ -719,8 +725,8 @@ vlog_init(void)
         unixctl_command_register(
             "vlog/set", "{spec | PATTERN:destination:pattern}",
             1, INT_MAX, vlog_unixctl_set, NULL);
-        unixctl_command_register("vlog/list", "", 0, 0, vlog_unixctl_list,
-                                 NULL);
+        unixctl_command_register("vlog/list", "[PATTERN]", 0, 1,
+                                 vlog_unixctl_list, NULL);
         unixctl_command_register("vlog/enable-rate-limit", "[module]...",
                                  0, INT_MAX, vlog_enable_rate_limit, NULL);
         unixctl_command_register("vlog/disable-rate-limit", "[module]...",
@@ -785,6 +791,32 @@ vlog_get_levels(void)
     return ds_cstr(&s);
 }
 
+/* Returns as a string current logging patterns for each destination.
+ * This string must be released by caller. */
+char *
+vlog_get_patterns(void)
+{
+    struct ds ds = DS_EMPTY_INITIALIZER;
+    enum vlog_destination destination;
+
+    ovs_rwlock_rdlock(&pattern_rwlock);
+    ds_put_format(&ds, "         prefix                            format\n");
+    ds_put_format(&ds, "         ------                            ------\n");
+
+    for (destination = 0; destination < VLF_N_DESTINATIONS; destination++) {
+        struct destination *f = &destinations[destination];;
+        const char *prefix = "none";
+
+        if (destination == VLF_SYSLOG && syslogger) {
+            prefix = syslog_get_prefix(syslogger);
+        }
+        ds_put_format(&ds, "%-7s  %-32s  %s\n", f->name, prefix, f->pattern);
+    }
+    ovs_rwlock_unlock(&pattern_rwlock);
+
+    return ds_cstr(&ds);
+}
+
 /* Returns true if a log message emitted for the given 'module' and 'level'
  * would cause some log output, false if that module and level are completely
  * disabled. */
diff --git a/utilities/ovs-appctl.8.in b/utilities/ovs-appctl.8.in
index 9e33f61..84633ac 100644
--- a/utilities/ovs-appctl.8.in
+++ b/utilities/ovs-appctl.8.in
@@ -109,8 +109,9 @@ messages at this level are not logged by default.
 .PP
 Every Open vSwitch daemon supports the following commands for examining
 and adjusting log levels.
-.IP "\fBvlog/list\fR"
-Lists the known logging modules and their current levels.
+.IP "\fBvlog/list\fR [\fIPATTERN\fR]"
+Lists the known logging modules and their current levels.  If \fIPATTERN\fR
+is set, then lists logging pattern used for each destination.
 .
 .IP "\fBvlog/set\fR [\fIspec\fR]"
 Sets logging levels.  Without any \fIspec\fR, sets the log level for
diff --git a/utilities/ovs-appctl.c b/utilities/ovs-appctl.c
index f7403f7..7fc72e3 100644
--- a/utilities/ovs-appctl.c
+++ b/utilities/ovs-appctl.c
@@ -91,7 +91,9 @@ Targets:\n\
 Common commands:\n\
   list-commands      List commands supported by the target\n\
   version            Print version of the target\n\
-  vlog/list          List current logging levels\n\
+  vlog/list [PATTERN]\n\
+      List current logging levels. If PATTERN is set,\n\
+      then instead list logging patterns used for each destination.\n\
   vlog/set [SPEC]\n\
       Set log levels as detailed in SPEC, which may include:\n\
       A valid module name (all modules, by default)\n\
-- 
2.1.4




More information about the dev mailing list