vlog: Be more liberal in syntax for -v and vlog/set.
authorBen Pfaff <blp@nicira.com>
Wed, 8 Feb 2012 23:29:15 +0000 (15:29 -0800)
committerBen Pfaff <blp@nicira.com>
Mon, 27 Feb 2012 17:25:04 +0000 (09:25 -0800)
Until now, the argument to -v and vlog/set has had to take the form
"module:facility:level".  I can never remember the required order, so this
commit switches to allowing any order.

Signed-off-by: Ben Pfaff <blp@nicira.com>
NEWS
lib/vlog-unixctl.man
lib/vlog.c
lib/vlog.man
utilities/ovs-appctl.8.in
utilities/ovs-appctl.c

diff --git a/NEWS b/NEWS
index 6e50b05..e92ccc7 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -27,9 +27,13 @@ v1.6.0 - xx xxx xxxx
     - When QoS settings for an interface do not configure a default queue
       (queue 0), Open vSwitch now uses a default configuration for that
       queue, instead of dropping all packets as in previous versions.
-    - Logging to console and file will have UTC timestamp as a default for all
-      the daemons. An example of the default format is 2012-01-27T16:35:17Z.
-      ovs-appctl can be used to change the default format as before.
+    - Logging:
+        - Logging to console and file will have UTC timestamp as a default for
+          all the daemons. An example of the default format is
+          2012-01-27T16:35:17Z.  ovs-appctl can be used to change the default
+          format as before.
+        - The syntax of commands and options to set log levels was simplified,
+          to make it easier to remember.
     - New support for limiting the number of flows in an OpenFlow flow
       table, with configurable policy for evicting flows upon
       overflow.  See the Flow_Table table in ovs-vswitch.conf.db(5)
index 31de844..567ac0e 100644 (file)
@@ -1,28 +1,39 @@
 .SS "VLOG COMMANDS"
 These commands manage \fB\*(PN\fR's logging settings.
-.IP "\fBvlog/set\fR \fImodule\fR[\fB:\fIfacility\fR[\fB:\fIlevel\fR]]"
-Sets the logging level for \fImodule\fR in \fIfacility\fR to
-\fIlevel\fR:
+.IP "\fBvlog/set\fR [\fIspec\fR]"
+Sets logging levels.  Without any \fIspec\fR, sets the log level for
+every module and facility to \fBdbg\fR.  Otherwise, \fIspec\fR is a
+list of words separated by spaces or commas or colons, up to one from
+each category below:
 .
 .RS
 .IP \(bu
-\fImodule\fR may be any valid module name (as displayed by the
-\fB\-\-list\fR action on \fBovs\-appctl\fR(8)), or the special name
-\fBANY\fR to set the logging levels for all modules.
+A valid module name, as displayed by the \fBvlog/list\fR command on
+\fBovs\-appctl\fR(8), limits the log level change to the specified
+module.
 .
 .IP \(bu
-\fIfacility\fR may be \fBsyslog\fR, \fBconsole\fR, or \fBfile\fR to
-set the levels for logging to the system log, the console, or a file
-respectively, or \fBANY\fR to set the logging levels for both
-facilities.  If it is omitted, \fIfacility\fR defaults to \fBANY\fR.
-.IP
-The log level for the \fBfile\fR facility has no effect unless
-\fB\*(PN\fR was invoked with the \fB\-\-log\-file\fR option.
+\fBsyslog\fR, \fBconsole\fR, or \fBfile\fR, to limit the log level
+change to only to the system log, to the console, or to a file,
+respectively.
+.
 .IP \(bu 
-\fIlevel\fR must be one of \fBoff\fR, \fBemer\fR, \fBerr\fR, \fBwarn\fR,
-\fBinfo\fR, or
-\fBdbg\fR, designating the minimum severity of a message for it to be
-logged.  If it is omitted, \fIlevel\fR defaults to \fBdbg\fR.
+\fBoff\fR, \fBemer\fR, \fBerr\fR, \fBwarn\fR, \fBinfo\fR, or
+\fBdbg\fR, to control the log level.  Messages of the given severity
+or higher will be logged, and messages of lower severity will be
+filtered out.  \fBoff\fR filters out all messages.  See
+\fBovs\-appctl\fR(8) for a definition of each log level.
+.RE
+.
+.IP
+Case is not significant within \fIspec\fR.
+.IP
+Regardless of the log levels set for \fBfile\fR, logging to a file
+will not take place unless \fB\*(PN\fR was invoked with the
+\fB\-\-log\-file\fR option.
+.IP
+For compatibility with older versions of OVS, \fBany\fR is accepted as
+a word but has no effect.
 .RE
 .IP "\fBvlog/set PATTERN:\fIfacility\fB:\fIpattern\fR"
 Sets the log pattern for \fIfacility\fR to \fIpattern\fR.  Refer to
index 5d92a4b..07ba5e0 100644 (file)
@@ -341,69 +341,78 @@ vlog_reopen_log_file(void)
     return vlog_set_log_file(log_file_name);
 }
 
-/* Set debugging levels:
- *
- *  mod[:facility[:level]] mod2[:facility[:level]] ...
- *
- * Return null if successful, otherwise an error message that the caller must
- * free().
- */
+/* Set debugging levels.  Returns null if successful, otherwise an error
+ * message that the caller must free(). */
 char *
 vlog_set_levels_from_string(const char *s_)
 {
-    char *save_ptr = NULL;
     char *s = xstrdup(s_);
-    char *module, *facility;
-
-    for (module = strtok_r(s, ": \t", &save_ptr); module != NULL;
-         module = strtok_r(NULL, ": \t", &save_ptr)) {
-        struct vlog_module *e_module;
-        enum vlog_facility e_facility;
+    char *save_ptr = NULL;
+    char *msg = NULL;
+    char *word;
 
-        facility = strtok_r(NULL, ":", &save_ptr);
+    word = strtok_r(s, " ,:\t", &save_ptr);
+    if (word && !strcasecmp(word, "PATTERN")) {
+        enum vlog_facility facility;
 
-        if (!facility || !strcasecmp(facility, "ANY")) {
-            e_facility = VLF_ANY_FACILITY;
-        } else {
-            e_facility = vlog_get_facility_val(facility);
-            if (e_facility >= VLF_N_FACILITIES) {
-                char *msg = xasprintf("unknown facility \"%s\"", facility);
-                free(s);
-                return msg;
-            }
+        word = strtok_r(NULL, " ,:\t", &save_ptr);
+        if (!word) {
+            msg = xstrdup("missing facility");
+            goto exit;
         }
 
-        if (!strcasecmp(module, "PATTERN")) {
-            vlog_set_pattern(e_facility, save_ptr);
-            break;
-        } else {
-            char *level;
-            enum vlog_level e_level;
-
-            if (!strcasecmp(module, "ANY")) {
-                e_module = NULL;
-            } else {
-                e_module = vlog_module_from_name(module);
-                if (!e_module) {
-                    char *msg = xasprintf("unknown module \"%s\"", module);
-                    free(s);
-                    return msg;
+        facility = (!strcasecmp(word, "ANY")
+                    ? VLF_ANY_FACILITY
+                    : vlog_get_facility_val(word));
+        if (facility == VLF_N_FACILITIES) {
+            msg = xasprintf("unknown facility \"%s\"", word);
+            goto exit;
+        }
+        vlog_set_pattern(facility, save_ptr);
+    } else {
+        struct vlog_module *module = NULL;
+        enum vlog_level level = VLL_N_LEVELS;
+        enum vlog_facility facility = VLF_N_FACILITIES;
+
+        for (; word != NULL; word = strtok_r(NULL, " ,:\t", &save_ptr)) {
+            if (!strcasecmp(word, "ANY")) {
+                continue;
+            } else if (vlog_get_facility_val(word) != VLF_N_FACILITIES) {
+                if (facility != VLF_N_FACILITIES) {
+                    msg = xstrdup("cannot specify multiple facilities");
+                    goto exit;
                 }
+                facility = vlog_get_facility_val(word);
+            } else if (vlog_get_level_val(word) != VLL_N_LEVELS) {
+                if (level != VLL_N_LEVELS) {
+                    msg = xstrdup("cannot specify multiple levels");
+                    goto exit;
+                }
+                level = vlog_get_level_val(word);
+            } else if (vlog_module_from_name(word)) {
+                if (module) {
+                    msg = xstrdup("cannot specify multiple modules");
+                    goto exit;
+                }
+                module = vlog_module_from_name(word);
+            } else {
+                msg = xasprintf("no facility, level, or module \"%s\"", word);
+                goto exit;
             }
+        }
 
-            level = strtok_r(NULL, ":", &save_ptr);
-            e_level = level ? vlog_get_level_val(level) : VLL_DBG;
-            if (e_level >= VLL_N_LEVELS) {
-                char *msg = xasprintf("unknown level \"%s\"", level);
-                free(s);
-                return msg;
-            }
-
-            vlog_set_levels(e_module, e_facility, e_level);
+        if (facility == VLF_N_FACILITIES) {
+            facility = VLF_ANY_FACILITY;
+        }
+        if (level == VLL_N_LEVELS) {
+            level = VLL_DBG;
         }
+        vlog_set_levels(module, facility, level);
     }
+
+exit:
     free(s);
-    return NULL;
+    return msg;
 }
 
 /* If 'arg' is null, configure maximum verbosity.  Otherwise, sets
@@ -488,7 +497,7 @@ vlog_init(void)
     }
 
     unixctl_command_register(
-        "vlog/set", "{module[:facility[:level]] | PATTERN:facility:pattern}",
+        "vlog/set", "{spec | PATTERN:facility:pattern}",
         1, INT_MAX, vlog_unixctl_set, NULL);
     unixctl_command_register("vlog/list", "", 0, 0, vlog_unixctl_list, NULL);
     unixctl_command_register("vlog/reopen", "", 0, 0,
@@ -808,7 +817,7 @@ void
 vlog_usage(void)
 {
     printf("\nLogging options:\n"
-           "  -v, --verbose=MODULE[:FACILITY[:LEVEL]]  set logging levels\n"
+           "  -v, --verbose=[SPEC]    set logging levels\n"
            "  -v, --verbose           set maximum verbosity level\n"
            "  --log-file[=FILE]       enable logging to specified FILE\n"
            "                          (default: %s/%s.log)\n",
index a2316da..a8c8223 100644 (file)
@@ -3,36 +3,43 @@
 .  ns
 .  IP "\\$1"
 ..
-.IP "\fB\-v\fImodule\fR[\fB:\fIfacility\fR[\fB:\fIlevel\fR]]"
-.IQ "\fB\-\-verbose=\fImodule\fR[\fB:\fIfacility\fR[\fB:\fIlevel\fR]]"
+.IP "\fB\-v\fR[\fIspec\fR]
+.IQ "\fB\-\-verbose=\fR[\fIspec\fR]
 .
-Sets the logging level for \fImodule\fR in \fIfacility\fR to
-\fIlevel\fR:
+Sets logging levels.  Without any \fIspec\fR, sets the log level for
+every module and facility to \fBdbg\fR.  Otherwise, \fIspec\fR is a
+list of words separated by spaces or commas or colons, up to one from
+each category below:
 .
 .RS
 .IP \(bu
-\fImodule\fR may be any valid module name (as displayed by the
-\fB\-\-list\fR action on \fBovs\-appctl\fR(8)), or the special name
-\fBANY\fR to set the logging levels for all modules.
+A valid module name, as displayed by the \fBvlog/list\fR command on
+\fBovs\-appctl\fR(8), limits the log level change to the specified
+module.
 .
 .IP \(bu
-\fIfacility\fR may be \fBsyslog\fR, \fBconsole\fR, or \fBfile\fR to
-set the levels for logging to the system log, the console, or a file
-respectively, or \fBANY\fR to set the logging levels for both
-facilities.  If it is omitted, \fIfacility\fR defaults to \fBANY\fR.
-.IP
-Regardless of the log levels set for \fBfile\fR, logging to a file
-will not take place unless \fB\-\-log\-file\fR is also specified (see
-below).
+\fBsyslog\fR, \fBconsole\fR, or \fBfile\fR, to limit the log level
+change to only to the system log, to the console, or to a file,
+respectively.
 .
 .IP \(bu 
-\fIlevel\fR must be one of \fBoff\fR, \fBemer\fR, \fBerr\fR, \fBwarn\fR,
-\fBinfo\fR, or
-\fBdbg\fR, designating the minimum severity of a message for it to be
-logged.  If it is omitted, \fIlevel\fR defaults to \fBdbg\fR.  See
+\fBoff\fR, \fBemer\fR, \fBerr\fR, \fBwarn\fR, \fBinfo\fR, or
+\fBdbg\fR, to control the log level.  Messages of the given severity
+or higher will be logged, and messages of lower severity will be
+filtered out.  \fBoff\fR filters out all messages.  See
 \fBovs\-appctl\fR(8) for a definition of each log level.
 .RE
 .
+.IP
+Case is not significant within \fIspec\fR.
+.IP
+Regardless of the log levels set for \fBfile\fR, logging to a file
+will not take place unless \fB\-\-log\-file\fR is also specified (see
+below).
+.IP
+For compatibility with older versions of OVS, \fBany\fR is accepted as
+a word but has no effect.
+.
 .IP "\fB\-v\fR"
 .IQ "\fB\-\-verbose\fR"
 Sets the maximum logging verbosity level, equivalent to
index 6a61732..38ed8c9 100644 (file)
@@ -72,26 +72,26 @@ Displays the version and compilation date of the target.
 .SS LOGGING COMMANDS
 Open vSwitch has several log levels.  The highest-severity log level is:
 .
-.IP "\fBOFF\fR"
+.IP "\fBoff\fR"
 No message is ever logged at this level, so setting a logging
-facility's log level to \fBOFF\fR disables logging to that facility.
+facility's log level to \fBoff\fR disables logging to that facility.
 .
 .PP
 The following log levels, in order of descending severity, are
 available:
 .
-.IP "\fBEMER\fR"
+.IP "\fBemer\fR"
 A major failure forced a process to abort.
-.IP "\fBERR\fR"
+.IP "\fBerr\fR"
 A high-level operation or a subsystem failed.  Attention is
 warranted.
-.IP "\fBWARN\fR"
+.IP "\fBwarn\fR"
 A low-level operation failed, but higher-level subsystems may be able
 to recover.
-.IP "\fBINFO\fR"
+.IP "\fBinfo\fR"
 Information that may be useful in retrospect when investigating
 a problem.
-.IP "\fBDBG\fR"
+.IP "\fBdbg\fR"
 Information useful only to someone with intricate knowledge of the
 system, or that would commonly cause too-voluminous log output.  Log
 messages at this level are not logged by default.
@@ -102,20 +102,39 @@ and adjusting log levels.
 .IP "\fBvlog/list\fR"
 Lists the known logging modules and their current levels.
 .
-.IP "\fBvlog/set\fR \fImodule\fR[\fB:\fIfacility\fR[\fB:\fIlevel\fR]]"
-Sets the logging level for \fImodule\fR in \fIfacility\fR to
-\fIlevel\fR.  The \fImodule\fR may be any valid module name (as
-displayed by the \fB\-\-list\fR option) or the special name \fBANY\fR to
-set the logging levels for all modules.  The \fIfacility\fR may be
-\fBsyslog\fR, \fBconsole\fR or \fBfile\fR to set the levels for logging to
-the system log, console or a file, respectively, or \fBANY\fR to set the
-logging levels for all facilities.  If it is omitted,
-\fIfacility\fR defaults to \fBANY\fR. Regardless of the log levels set for
-\fBfile\fR, logging to a file will not take place unless the target application
-was invoked with the \fB\-\-logfile\fR option. The \fIlevel\fR must be one of
+.IP "\fBvlog/set\fR [\fIspec\fR]"
+Sets logging levels.  Without any \fIspec\fR, sets the log level for
+every module and facility to \fBdbg\fR.  Otherwise, \fIspec\fR is a
+list of words separated by spaces or commas or colons, up to one from
+each category below:
+.
+.RS
+.IP \(bu
+A valid module name, as displayed by the \fBvlog/list\fR command on
+\fBovs\-appctl\fR(8), limits the log level change to the specified
+module.
+.
+.IP \(bu
+\fBsyslog\fR, \fBconsole\fR, or \fBfile\fR, to limit the log level
+change to only to the system log, to the console, or to a file,
+respectively.
+.
+.IP \(bu 
 \fBoff\fR, \fBemer\fR, \fBerr\fR, \fBwarn\fR, \fBinfo\fR, or
-\fBdbg\fR, designating the minimum severity of a message for it to be logged.
-If it is omitted, \fIlevel\fR defaults to \fBdbg\fR.
+\fBdbg\fR, to control the log level.  Messages of the given severity
+or higher will be logged, and messages of lower severity will be
+filtered out.  \fBoff\fR filters out all messages.
+.RE
+.
+.IP
+Case is not significant within \fIspec\fR.
+.IP
+Regardless of the log levels set for \fBfile\fR, logging to a file
+will not take place unless the target application was invoked with the
+\fB\-\-log\-file\fR option.
+.IP
+For compatibility with older versions of OVS, \fBany\fR is accepted as
+a word but has no effect.
 .
 .IP "\fBvlog/set PATTERN:\fIfacility\fB:\fIpattern\fR"
 Sets the log pattern for \fIfacility\fR to \fIpattern\fR.  Each time a
index e528af3..ebfd54a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks.
+ * Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -82,11 +82,11 @@ Common commands:\n\
   help               List commands supported by the target\n\
   version            Print version of the target\n\
   vlog/list          List current logging levels\n\
-  vlog/set MODULE[:FACILITY[:LEVEL]]\n\
-      Set MODULE and FACILITY log level to LEVEL\n\
-      MODULE may be any valid module name or 'ANY'\n\
-      FACILITY may be 'syslog', 'console', 'file', or 'ANY' (default)\n\
-      LEVEL may be 'off', 'emer', 'err', 'warn', 'info', or 'dbg' (default)\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\
+      'syslog', 'console', 'file' (all facilities, by default))\n\
+      'off', 'emer', 'err', 'warn', 'info', or 'dbg' ('dbg', bydefault)\n\
   vlog/reopen        Make the program reopen its log file\n\
 Other options:\n\
   -h, --help         Print this helpful information\n\