2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-22 09:58:01 +00:00

vlog: Be more liberal in syntax for -v and vlog/set.

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>
This commit is contained in:
Ben Pfaff 2012-02-08 15:29:15 -08:00
parent 91005f0313
commit 2a3e30b27d
6 changed files with 166 additions and 116 deletions

10
NEWS
View File

@ -27,9 +27,13 @@ v1.6.0 - xx xxx xxxx
- When QoS settings for an interface do not configure a default queue - When QoS settings for an interface do not configure a default queue
(queue 0), Open vSwitch now uses a default configuration for that (queue 0), Open vSwitch now uses a default configuration for that
queue, instead of dropping all packets as in previous versions. queue, instead of dropping all packets as in previous versions.
- Logging to console and file will have UTC timestamp as a default for all - Logging:
the daemons. An example of the default format is 2012-01-27T16:35:17Z. - Logging to console and file will have UTC timestamp as a default for
ovs-appctl can be used to change the default format as before. 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 - New support for limiting the number of flows in an OpenFlow flow
table, with configurable policy for evicting flows upon table, with configurable policy for evicting flows upon
overflow. See the Flow_Table table in ovs-vswitch.conf.db(5) overflow. See the Flow_Table table in ovs-vswitch.conf.db(5)

View File

@ -1,28 +1,39 @@
.SS "VLOG COMMANDS" .SS "VLOG COMMANDS"
These commands manage \fB\*(PN\fR's logging settings. These commands manage \fB\*(PN\fR's logging settings.
.IP "\fBvlog/set\fR \fImodule\fR[\fB:\fIfacility\fR[\fB:\fIlevel\fR]]" .IP "\fBvlog/set\fR [\fIspec\fR]"
Sets the logging level for \fImodule\fR in \fIfacility\fR to Sets logging levels. Without any \fIspec\fR, sets the log level for
\fIlevel\fR: 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 .RS
.IP \(bu .IP \(bu
\fImodule\fR may be any valid module name (as displayed by the A valid module name, as displayed by the \fBvlog/list\fR command on
\fB\-\-list\fR action on \fBovs\-appctl\fR(8)), or the special name \fBovs\-appctl\fR(8), limits the log level change to the specified
\fBANY\fR to set the logging levels for all modules. module.
. .
.IP \(bu .IP \(bu
\fIfacility\fR may be \fBsyslog\fR, \fBconsole\fR, or \fBfile\fR to \fBsyslog\fR, \fBconsole\fR, or \fBfile\fR, to limit the log level
set the levels for logging to the system log, the console, or a file change to only to the system log, to the console, or to a file,
respectively, or \fBANY\fR to set the logging levels for both respectively.
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.
.IP \(bu .IP \(bu
\fIlevel\fR must be one of \fBoff\fR, \fBemer\fR, \fBerr\fR, \fBwarn\fR, \fBoff\fR, \fBemer\fR, \fBerr\fR, \fBwarn\fR, \fBinfo\fR, or
\fBinfo\fR, or \fBdbg\fR, to control the log level. Messages of the given severity
\fBdbg\fR, designating the minimum severity of a message for it to be or higher will be logged, and messages of lower severity will be
logged. If it is omitted, \fIlevel\fR defaults to \fBdbg\fR. 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 .RE
.IP "\fBvlog/set PATTERN:\fIfacility\fB:\fIpattern\fR" .IP "\fBvlog/set PATTERN:\fIfacility\fB:\fIpattern\fR"
Sets the log pattern for \fIfacility\fR to \fIpattern\fR. Refer to Sets the log pattern for \fIfacility\fR to \fIpattern\fR. Refer to

View File

@ -341,69 +341,78 @@ vlog_reopen_log_file(void)
return vlog_set_log_file(log_file_name); return vlog_set_log_file(log_file_name);
} }
/* Set debugging levels: /* Set debugging levels. Returns null if successful, otherwise an error
* * message that the caller must free(). */
* mod[:facility[:level]] mod2[:facility[:level]] ...
*
* Return null if successful, otherwise an error message that the caller must
* free().
*/
char * char *
vlog_set_levels_from_string(const char *s_) vlog_set_levels_from_string(const char *s_)
{ {
char *save_ptr = NULL;
char *s = xstrdup(s_); char *s = xstrdup(s_);
char *module, *facility; char *save_ptr = NULL;
char *msg = NULL;
char *word;
for (module = strtok_r(s, ": \t", &save_ptr); module != NULL; word = strtok_r(s, " ,:\t", &save_ptr);
module = strtok_r(NULL, ": \t", &save_ptr)) { if (word && !strcasecmp(word, "PATTERN")) {
struct vlog_module *e_module; enum vlog_facility facility;
enum vlog_facility e_facility;
facility = strtok_r(NULL, ":", &save_ptr); word = strtok_r(NULL, " ,:\t", &save_ptr);
if (!word) {
if (!facility || !strcasecmp(facility, "ANY")) { msg = xstrdup("missing facility");
e_facility = VLF_ANY_FACILITY; goto exit;
} 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;
}
} }
if (!strcasecmp(module, "PATTERN")) { facility = (!strcasecmp(word, "ANY")
vlog_set_pattern(e_facility, save_ptr); ? VLF_ANY_FACILITY
break; : vlog_get_facility_val(word));
} else { if (facility == VLF_N_FACILITIES) {
char *level; msg = xasprintf("unknown facility \"%s\"", word);
enum vlog_level e_level; 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;
if (!strcasecmp(module, "ANY")) { for (; word != NULL; word = strtok_r(NULL, " ,:\t", &save_ptr)) {
e_module = NULL; if (!strcasecmp(word, "ANY")) {
} else { continue;
e_module = vlog_module_from_name(module); } else if (vlog_get_facility_val(word) != VLF_N_FACILITIES) {
if (!e_module) { if (facility != VLF_N_FACILITIES) {
char *msg = xasprintf("unknown module \"%s\"", module); msg = xstrdup("cannot specify multiple facilities");
free(s); goto exit;
return msg;
} }
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); free(s);
return NULL; return msg;
} }
/* If 'arg' is null, configure maximum verbosity. Otherwise, sets /* If 'arg' is null, configure maximum verbosity. Otherwise, sets
@ -488,7 +497,7 @@ vlog_init(void)
} }
unixctl_command_register( unixctl_command_register(
"vlog/set", "{module[:facility[:level]] | PATTERN:facility:pattern}", "vlog/set", "{spec | PATTERN:facility:pattern}",
1, INT_MAX, vlog_unixctl_set, NULL); 1, INT_MAX, vlog_unixctl_set, NULL);
unixctl_command_register("vlog/list", "", 0, 0, vlog_unixctl_list, NULL); unixctl_command_register("vlog/list", "", 0, 0, vlog_unixctl_list, NULL);
unixctl_command_register("vlog/reopen", "", 0, 0, unixctl_command_register("vlog/reopen", "", 0, 0,
@ -808,7 +817,7 @@ void
vlog_usage(void) vlog_usage(void)
{ {
printf("\nLogging options:\n" 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" " -v, --verbose set maximum verbosity level\n"
" --log-file[=FILE] enable logging to specified FILE\n" " --log-file[=FILE] enable logging to specified FILE\n"
" (default: %s/%s.log)\n", " (default: %s/%s.log)\n",

View File

@ -3,35 +3,42 @@
. ns . ns
. IP "\\$1" . IP "\\$1"
.. ..
.IP "\fB\-v\fImodule\fR[\fB:\fIfacility\fR[\fB:\fIlevel\fR]]" .IP "\fB\-v\fR[\fIspec\fR]
.IQ "\fB\-\-verbose=\fImodule\fR[\fB:\fIfacility\fR[\fB:\fIlevel\fR]]" .IQ "\fB\-\-verbose=\fR[\fIspec\fR]
. .
Sets the logging level for \fImodule\fR in \fIfacility\fR to Sets logging levels. Without any \fIspec\fR, sets the log level for
\fIlevel\fR: 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 .RS
.IP \(bu .IP \(bu
\fImodule\fR may be any valid module name (as displayed by the A valid module name, as displayed by the \fBvlog/list\fR command on
\fB\-\-list\fR action on \fBovs\-appctl\fR(8)), or the special name \fBovs\-appctl\fR(8), limits the log level change to the specified
\fBANY\fR to set the logging levels for all modules. module.
. .
.IP \(bu .IP \(bu
\fIfacility\fR may be \fBsyslog\fR, \fBconsole\fR, or \fBfile\fR to \fBsyslog\fR, \fBconsole\fR, or \fBfile\fR, to limit the log level
set the levels for logging to the system log, the console, or a file change to only to the system log, to the console, or to a file,
respectively, or \fBANY\fR to set the logging levels for both respectively.
facilities. If it is omitted, \fIfacility\fR defaults to \fBANY\fR. .
.IP \(bu
\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 .IP
Regardless of the log levels set for \fBfile\fR, logging to a file 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 will not take place unless \fB\-\-log\-file\fR is also specified (see
below). below).
. .IP
.IP \(bu For compatibility with older versions of OVS, \fBany\fR is accepted as
\fIlevel\fR must be one of \fBoff\fR, \fBemer\fR, \fBerr\fR, \fBwarn\fR, a word but has no effect.
\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
\fBovs\-appctl\fR(8) for a definition of each log level.
.RE
. .
.IP "\fB\-v\fR" .IP "\fB\-v\fR"
.IQ "\fB\-\-verbose\fR" .IQ "\fB\-\-verbose\fR"

View File

@ -72,26 +72,26 @@ Displays the version and compilation date of the target.
.SS LOGGING COMMANDS .SS LOGGING COMMANDS
Open vSwitch has several log levels. The highest-severity log level is: 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 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 .PP
The following log levels, in order of descending severity, are The following log levels, in order of descending severity, are
available: available:
. .
.IP "\fBEMER\fR" .IP "\fBemer\fR"
A major failure forced a process to abort. A major failure forced a process to abort.
.IP "\fBERR\fR" .IP "\fBerr\fR"
A high-level operation or a subsystem failed. Attention is A high-level operation or a subsystem failed. Attention is
warranted. warranted.
.IP "\fBWARN\fR" .IP "\fBwarn\fR"
A low-level operation failed, but higher-level subsystems may be able A low-level operation failed, but higher-level subsystems may be able
to recover. to recover.
.IP "\fBINFO\fR" .IP "\fBinfo\fR"
Information that may be useful in retrospect when investigating Information that may be useful in retrospect when investigating
a problem. a problem.
.IP "\fBDBG\fR" .IP "\fBdbg\fR"
Information useful only to someone with intricate knowledge of the Information useful only to someone with intricate knowledge of the
system, or that would commonly cause too-voluminous log output. Log system, or that would commonly cause too-voluminous log output. Log
messages at this level are not logged by default. messages at this level are not logged by default.
@ -102,20 +102,39 @@ and adjusting log levels.
.IP "\fBvlog/list\fR" .IP "\fBvlog/list\fR"
Lists the known logging modules and their current levels. Lists the known logging modules and their current levels.
. .
.IP "\fBvlog/set\fR \fImodule\fR[\fB:\fIfacility\fR[\fB:\fIlevel\fR]]" .IP "\fBvlog/set\fR [\fIspec\fR]"
Sets the logging level for \fImodule\fR in \fIfacility\fR to Sets logging levels. Without any \fIspec\fR, sets the log level for
\fIlevel\fR. The \fImodule\fR may be any valid module name (as every module and facility to \fBdbg\fR. Otherwise, \fIspec\fR is a
displayed by the \fB\-\-list\fR option) or the special name \fBANY\fR to list of words separated by spaces or commas or colons, up to one from
set the logging levels for all modules. The \fIfacility\fR may be each category below:
\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 .RS
logging levels for all facilities. If it is omitted, .IP \(bu
\fIfacility\fR defaults to \fBANY\fR. Regardless of the log levels set for A valid module name, as displayed by the \fBvlog/list\fR command on
\fBfile\fR, logging to a file will not take place unless the target application \fBovs\-appctl\fR(8), limits the log level change to the specified
was invoked with the \fB\-\-logfile\fR option. The \fIlevel\fR must be one of 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 \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. \fBdbg\fR, to control the log level. Messages of the given severity
If it is omitted, \fIlevel\fR defaults to \fBdbg\fR. 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" .IP "\fBvlog/set PATTERN:\fIfacility\fB:\fIpattern\fR"
Sets the log pattern for \fIfacility\fR to \fIpattern\fR. Each time a Sets the log pattern for \fIfacility\fR to \fIpattern\fR. Each time a

View 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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\ help List commands supported by the target\n\
version Print version of the target\n\ version Print version of the target\n\
vlog/list List current logging levels\n\ vlog/list List current logging levels\n\
vlog/set MODULE[:FACILITY[:LEVEL]]\n\ vlog/set [SPEC]\n\
Set MODULE and FACILITY log level to LEVEL\n\ Set log levels as detailed in SPEC, which may include:\n\
MODULE may be any valid module name or 'ANY'\n\ A valid module name (all modules, by default)\n\
FACILITY may be 'syslog', 'console', 'file', or 'ANY' (default)\n\ 'syslog', 'console', 'file' (all facilities, by default))\n\
LEVEL may be 'off', 'emer', 'err', 'warn', 'info', or 'dbg' (default)\n\ 'off', 'emer', 'err', 'warn', 'info', or 'dbg' ('dbg', bydefault)\n\
vlog/reopen Make the program reopen its log file\n\ vlog/reopen Make the program reopen its log file\n\
Other options:\n\ Other options:\n\
-h, --help Print this helpful information\n\ -h, --help Print this helpful information\n\