2
0
mirror of https://github.com/openvswitch/ovs synced 2025-08-30 22:05:19 +00:00

vlog: Rename the currently used term 'facility' as 'destination'.

In OVS, we currently use the term 'facility' to mean the place
where we log (syslog, console or file). In Linux's syslog() and
rfc5424, the term 'facility' is used to specify what type of program
is logging the message (e.g: LOG_DAEMON). This causes confusion
while reading vlog's code. This commit changes the term 'facility'
to 'destination'.

Signed-off-by: Gurucharan Shetty <gshetty@nicira.com>
Acked-by: Ben Pfaff <blp@nicira.com>
This commit is contained in:
Gurucharan Shetty
2015-01-06 13:05:00 -08:00
parent 4c75aaabb1
commit d5460484c3
17 changed files with 163 additions and 150 deletions

3
NEWS
View File

@@ -53,6 +53,9 @@ Post-v2.3.0
This is generic tunneling mechanism for userspace datapath. This is generic tunneling mechanism for userspace datapath.
- Support for multicast snooping (IGMPv1 and IGMPv2) - Support for multicast snooping (IGMPv1 and IGMPv2)
- Support for Linux kernels up to 3.18.x - Support for Linux kernels up to 3.18.x
- The documentation now use the term 'destination' to mean one of syslog,
console or file for vlog logging instead of the previously used term
'facility'.
v2.3.0 - 14 Aug 2014 v2.3.0 - 14 Aug 2014

View File

@@ -60,28 +60,29 @@ enum vlog_level {
const char *vlog_get_level_name(enum vlog_level); const char *vlog_get_level_name(enum vlog_level);
enum vlog_level vlog_get_level_val(const char *name); enum vlog_level vlog_get_level_val(const char *name);
/* Facilities that we can log to. */ /* Destinations that we can log to. */
#define VLOG_FACILITIES \ #define VLOG_DESTINATIONS \
VLOG_FACILITY(SYSLOG, "ovs|%05N|%c%T|%p|%m") \ VLOG_DESTINATION(SYSLOG, "ovs|%05N|%c%T|%p|%m") \
VLOG_FACILITY(CONSOLE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c%T|%p|%m") \ VLOG_DESTINATION(CONSOLE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c%T|%p|%m") \
VLOG_FACILITY(FILE, "%D{%Y-%m-%dT%H:%M:%S.###Z}|%05N|%c%T|%p|%m") VLOG_DESTINATION(FILE, "%D{%Y-%m-%dT%H:%M:%S.###Z}|%05N|%c%T|%p|%m")
enum vlog_facility { enum vlog_destination {
#define VLOG_FACILITY(NAME, PATTERN) VLF_##NAME, #define VLOG_DESTINATION(NAME, PATTERN) VLF_##NAME,
VLOG_FACILITIES VLOG_DESTINATIONS
#undef VLOG_FACILITY #undef VLOG_DESTINATION
VLF_N_FACILITIES, VLF_N_DESTINATIONS,
VLF_ANY_FACILITY = -1 VLF_ANY_DESTINATION = -1
}; };
const char *vlog_get_facility_name(enum vlog_facility); const char *vlog_get_destination_name(enum vlog_destination);
enum vlog_facility vlog_get_facility_val(const char *name); enum vlog_destination vlog_get_destination_val(const char *name);
/* A log module. */ /* A log module. */
struct vlog_module { struct vlog_module {
struct ovs_list list; struct ovs_list list;
const char *name; /* User-visible name. */ const char *name; /* User-visible name. */
int levels[VLF_N_FACILITIES]; /* Minimum log level for each facility. */ int levels[VLF_N_DESTINATIONS]; /* Minimum log level for each
int min_level; /* Minimum log level for any facility. */ destination. */
int min_level; /* Minimum log level for any destination. */
bool honor_rate_limits; /* Set false to ignore rate limits. */ bool honor_rate_limits; /* Set false to ignore rate limits. */
}; };
@@ -125,9 +126,10 @@ struct vlog_rate_limit {
} }
/* Configuring how each module logs messages. */ /* Configuring how each module logs messages. */
enum vlog_level vlog_get_level(const struct vlog_module *, enum vlog_facility); enum vlog_level vlog_get_level(const struct vlog_module *,
enum vlog_destination);
void vlog_set_levels(struct vlog_module *, void vlog_set_levels(struct vlog_module *,
enum vlog_facility, enum vlog_level); enum vlog_destination, enum vlog_level);
char *vlog_set_levels_from_string(const char *) OVS_WARN_UNUSED_RESULT; char *vlog_set_levels_from_string(const char *) OVS_WARN_UNUSED_RESULT;
void vlog_set_levels_from_string_assert(const char *); void vlog_set_levels_from_string_assert(const char *);
char *vlog_get_levels(void); char *vlog_get_levels(void);
@@ -136,8 +138,8 @@ bool vlog_should_drop(const struct vlog_module *, enum vlog_level,
struct vlog_rate_limit *); struct vlog_rate_limit *);
void vlog_set_verbosity(const char *arg); void vlog_set_verbosity(const char *arg);
/* Configuring log facilities. */ /* Configuring log destinations. */
void vlog_set_pattern(enum vlog_facility, const char *pattern); void vlog_set_pattern(enum vlog_destination, const char *pattern);
int vlog_set_log_file(const char *file_name); int vlog_set_log_file(const char *file_name);
int vlog_reopen_log_file(void); int vlog_reopen_log_file(void);

View File

@@ -1,6 +1,6 @@
.IP "Logging options:" .IP "Logging options:"
[\fB\-v\fR[\fImodule\fR[\fB:\fIfacility\fR[\fB:\fIlevel\fR]]]]\&... [\fB\-v\fR[\fImodule\fR[\fB:\fIdestination\fR[\fB:\fIlevel\fR]]]]\&...
.br .br
[\fB\-\-verbose[=\fImodule\fR[\fB:\fIfacility\fR[\fB:\fIlevel\fR]]]]\&... [\fB\-\-verbose[=\fImodule\fR[\fB:\fIdestination\fR[\fB:\fIlevel\fR]]]]\&...
.br .br
[\fB\-\-log\-file\fR[\fB=\fIfile\fR]] [\fB\-\-log\-file\fR[\fB=\fIfile\fR]]

View File

@@ -7,7 +7,7 @@
These commands manage \fB\*(PN\fR's logging settings. These commands manage \fB\*(PN\fR's logging settings.
.IP "\fBvlog/set\fR [\fIspec\fR]" .IP "\fBvlog/set\fR [\fIspec\fR]"
Sets logging levels. Without any \fIspec\fR, sets the log level for Sets logging levels. Without any \fIspec\fR, sets the log level for
every module and facility to \fBdbg\fR. Otherwise, \fIspec\fR is a every module and destination to \fBdbg\fR. Otherwise, \fIspec\fR is a
list of words separated by spaces or commas or colons, up to one from list of words separated by spaces or commas or colons, up to one from
each category below: each category below:
. .
@@ -44,8 +44,8 @@ will not take place unless \fB\*(PN\fR was invoked with the
For compatibility with older versions of OVS, \fBany\fR is accepted as For compatibility with older versions of OVS, \fBany\fR is accepted as
a word but has no effect. a word but has no effect.
.RE .RE
.IP "\fBvlog/set PATTERN:\fIfacility\fB:\fIpattern\fR" .IP "\fBvlog/set PATTERN:\fIdestination\fB:\fIpattern\fR"
Sets the log pattern for \fIfacility\fR to \fIpattern\fR. Refer to Sets the log pattern for \fIdestination\fR to \fIpattern\fR. Refer to
\fBovs\-appctl\fR(8) for a description of the valid syntax for \fIpattern\fR. \fBovs\-appctl\fR(8) for a description of the valid syntax for \fIpattern\fR.
. .
.IP "\fBvlog/list\fR" .IP "\fBvlog/list\fR"

View File

@@ -77,21 +77,21 @@ BUILD_ASSERT_DECL(LOG_LOCAL0 == (16 << 3));
/* The log modules. */ /* The log modules. */
struct ovs_list vlog_modules = OVS_LIST_INITIALIZER(&vlog_modules); struct ovs_list vlog_modules = OVS_LIST_INITIALIZER(&vlog_modules);
/* Protects the 'pattern' in all "struct facility"s, so that a race between /* Protects the 'pattern' in all "struct destination"s, so that a race between
* changing and reading the pattern does not cause an access to freed * changing and reading the pattern does not cause an access to freed
* memory. */ * memory. */
static struct ovs_rwlock pattern_rwlock = OVS_RWLOCK_INITIALIZER; static struct ovs_rwlock pattern_rwlock = OVS_RWLOCK_INITIALIZER;
/* Information about each facility. */ /* Information about each destination. */
struct facility { struct destination {
const char *name; /* Name. */ const char *name; /* Name. */
char *pattern OVS_GUARDED_BY(pattern_rwlock); /* Current pattern. */ char *pattern OVS_GUARDED_BY(pattern_rwlock); /* Current pattern. */
bool default_pattern; /* Whether current pattern is the default. */ bool default_pattern; /* Whether current pattern is the default. */
}; };
static struct facility facilities[VLF_N_FACILITIES] = { static struct destination destinations[VLF_N_DESTINATIONS] = {
#define VLOG_FACILITY(NAME, PATTERN) {#NAME, PATTERN, true}, #define VLOG_DESTINATION(NAME, PATTERN) {#NAME, PATTERN, true},
VLOG_FACILITIES VLOG_DESTINATIONS
#undef VLOG_FACILITY #undef VLOG_DESTINATION
}; };
/* Sequence number for the message currently being composed. */ /* Sequence number for the message currently being composed. */
@@ -147,23 +147,23 @@ vlog_get_level_val(const char *name)
return search_name_array(name, level_names, ARRAY_SIZE(level_names)); return search_name_array(name, level_names, ARRAY_SIZE(level_names));
} }
/* Returns the name for logging facility 'facility'. */ /* Returns the name for logging destination 'destination'. */
const char * const char *
vlog_get_facility_name(enum vlog_facility facility) vlog_get_destination_name(enum vlog_destination destination)
{ {
assert(facility < VLF_N_FACILITIES); assert(destination < VLF_N_DESTINATIONS);
return facilities[facility].name; return destinations[destination].name;
} }
/* Returns the logging facility named 'name', or VLF_N_FACILITIES if 'name' is /* Returns the logging destination named 'name', or VLF_N_DESTINATIONS if
* not the name of a logging facility. */ * 'name' is not the name of a logging destination. */
enum vlog_facility enum vlog_destination
vlog_get_facility_val(const char *name) vlog_get_destination_val(const char *name)
{ {
size_t i; size_t i;
for (i = 0; i < VLF_N_FACILITIES; i++) { for (i = 0; i < VLF_N_DESTINATIONS; i++) {
if (!strcasecmp(facilities[i].name, name)) { if (!strcasecmp(destinations[i].name, name)) {
break; break;
} }
} }
@@ -198,23 +198,25 @@ vlog_module_from_name(const char *name)
return NULL; return NULL;
} }
/* Returns the current logging level for the given 'module' and 'facility'. */ /* Returns the current logging level for the given 'module' and
* 'destination'. */
enum vlog_level enum vlog_level
vlog_get_level(const struct vlog_module *module, enum vlog_facility facility) vlog_get_level(const struct vlog_module *module,
enum vlog_destination destination)
{ {
assert(facility < VLF_N_FACILITIES); assert(destination < VLF_N_DESTINATIONS);
return module->levels[facility]; return module->levels[destination];
} }
static void static void
update_min_level(struct vlog_module *module) OVS_REQUIRES(&log_file_mutex) update_min_level(struct vlog_module *module) OVS_REQUIRES(&log_file_mutex)
{ {
enum vlog_facility facility; enum vlog_destination destination;
module->min_level = VLL_OFF; module->min_level = VLL_OFF;
for (facility = 0; facility < VLF_N_FACILITIES; facility++) { for (destination = 0; destination < VLF_N_DESTINATIONS; destination++) {
if (log_fd >= 0 || facility != VLF_FILE) { if (log_fd >= 0 || destination != VLF_FILE) {
enum vlog_level level = module->levels[facility]; enum vlog_level level = module->levels[destination];
if (level > module->min_level) { if (level > module->min_level) {
module->min_level = level; module->min_level = level;
} }
@@ -223,47 +225,49 @@ update_min_level(struct vlog_module *module) OVS_REQUIRES(&log_file_mutex)
} }
static void static void
set_facility_level(enum vlog_facility facility, struct vlog_module *module, set_destination_level(enum vlog_destination destination,
enum vlog_level level) struct vlog_module *module, enum vlog_level level)
{ {
assert(facility >= 0 && facility < VLF_N_FACILITIES); assert(destination >= 0 && destination < VLF_N_DESTINATIONS);
assert(level < VLL_N_LEVELS); assert(level < VLL_N_LEVELS);
ovs_mutex_lock(&log_file_mutex); ovs_mutex_lock(&log_file_mutex);
if (!module) { if (!module) {
struct vlog_module *mp; struct vlog_module *mp;
LIST_FOR_EACH (mp, list, &vlog_modules) { LIST_FOR_EACH (mp, list, &vlog_modules) {
mp->levels[facility] = level; mp->levels[destination] = level;
update_min_level(mp); update_min_level(mp);
} }
} else { } else {
module->levels[facility] = level; module->levels[destination] = level;
update_min_level(module); update_min_level(module);
} }
ovs_mutex_unlock(&log_file_mutex); ovs_mutex_unlock(&log_file_mutex);
} }
/* Sets the logging level for the given 'module' and 'facility' to 'level'. A /* Sets the logging level for the given 'module' and 'destination' to 'level'.
* null 'module' or a 'facility' of VLF_ANY_FACILITY is treated as a wildcard * A null 'module' or a 'destination' of VLF_ANY_DESTINATION is treated as a
* across all modules or facilities, respectively. */ * wildcard across all modules or destinations, respectively. */
void void
vlog_set_levels(struct vlog_module *module, enum vlog_facility facility, vlog_set_levels(struct vlog_module *module, enum vlog_destination destination,
enum vlog_level level) enum vlog_level level)
{ {
assert(facility < VLF_N_FACILITIES || facility == VLF_ANY_FACILITY); assert(destination < VLF_N_DESTINATIONS ||
if (facility == VLF_ANY_FACILITY) { destination == VLF_ANY_DESTINATION);
for (facility = 0; facility < VLF_N_FACILITIES; facility++) { if (destination == VLF_ANY_DESTINATION) {
set_facility_level(facility, module, level); for (destination = 0; destination < VLF_N_DESTINATIONS;
destination++) {
set_destination_level(destination, module, level);
} }
} else { } else {
set_facility_level(facility, module, level); set_destination_level(destination, module, level);
} }
} }
static void static void
do_set_pattern(enum vlog_facility facility, const char *pattern) do_set_pattern(enum vlog_destination destination, const char *pattern)
{ {
struct facility *f = &facilities[facility]; struct destination *f = &destinations[destination];
ovs_rwlock_wrlock(&pattern_rwlock); ovs_rwlock_wrlock(&pattern_rwlock);
if (!f->default_pattern) { if (!f->default_pattern) {
@@ -275,17 +279,19 @@ do_set_pattern(enum vlog_facility facility, const char *pattern)
ovs_rwlock_unlock(&pattern_rwlock); ovs_rwlock_unlock(&pattern_rwlock);
} }
/* Sets the pattern for the given 'facility' to 'pattern'. */ /* Sets the pattern for the given 'destination' to 'pattern'. */
void void
vlog_set_pattern(enum vlog_facility facility, const char *pattern) vlog_set_pattern(enum vlog_destination destination, const char *pattern)
{ {
assert(facility < VLF_N_FACILITIES || facility == VLF_ANY_FACILITY); assert(destination < VLF_N_DESTINATIONS ||
if (facility == VLF_ANY_FACILITY) { destination == VLF_ANY_DESTINATION);
for (facility = 0; facility < VLF_N_FACILITIES; facility++) { if (destination == VLF_ANY_DESTINATION) {
do_set_pattern(facility, pattern); for (destination = 0; destination < VLF_N_DESTINATIONS;
destination++) {
do_set_pattern(destination, pattern);
} }
} else { } else {
do_set_pattern(facility, pattern); do_set_pattern(destination, pattern);
} }
} }
@@ -397,36 +403,36 @@ vlog_set_levels_from_string(const char *s_)
word = strtok_r(s, " ,:\t", &save_ptr); word = strtok_r(s, " ,:\t", &save_ptr);
if (word && !strcasecmp(word, "PATTERN")) { if (word && !strcasecmp(word, "PATTERN")) {
enum vlog_facility facility; enum vlog_destination destination;
word = strtok_r(NULL, " ,:\t", &save_ptr); word = strtok_r(NULL, " ,:\t", &save_ptr);
if (!word) { if (!word) {
msg = xstrdup("missing facility"); msg = xstrdup("missing destination");
goto exit; goto exit;
} }
facility = (!strcasecmp(word, "ANY") destination = (!strcasecmp(word, "ANY")
? VLF_ANY_FACILITY ? VLF_ANY_DESTINATION
: vlog_get_facility_val(word)); : vlog_get_destination_val(word));
if (facility == VLF_N_FACILITIES) { if (destination == VLF_N_DESTINATIONS) {
msg = xasprintf("unknown facility \"%s\"", word); msg = xasprintf("unknown destination \"%s\"", word);
goto exit; goto exit;
} }
vlog_set_pattern(facility, save_ptr); vlog_set_pattern(destination, save_ptr);
} else { } else {
struct vlog_module *module = NULL; struct vlog_module *module = NULL;
enum vlog_level level = VLL_N_LEVELS; enum vlog_level level = VLL_N_LEVELS;
enum vlog_facility facility = VLF_N_FACILITIES; enum vlog_destination destination = VLF_N_DESTINATIONS;
for (; word != NULL; word = strtok_r(NULL, " ,:\t", &save_ptr)) { for (; word != NULL; word = strtok_r(NULL, " ,:\t", &save_ptr)) {
if (!strcasecmp(word, "ANY")) { if (!strcasecmp(word, "ANY")) {
continue; continue;
} else if (vlog_get_facility_val(word) != VLF_N_FACILITIES) { } else if (vlog_get_destination_val(word) != VLF_N_DESTINATIONS) {
if (facility != VLF_N_FACILITIES) { if (destination != VLF_N_DESTINATIONS) {
msg = xstrdup("cannot specify multiple facilities"); msg = xstrdup("cannot specify multiple destinations");
goto exit; goto exit;
} }
facility = vlog_get_facility_val(word); destination = vlog_get_destination_val(word);
} else if (vlog_get_level_val(word) != VLL_N_LEVELS) { } else if (vlog_get_level_val(word) != VLL_N_LEVELS) {
if (level != VLL_N_LEVELS) { if (level != VLL_N_LEVELS) {
msg = xstrdup("cannot specify multiple levels"); msg = xstrdup("cannot specify multiple levels");
@@ -440,18 +446,19 @@ vlog_set_levels_from_string(const char *s_)
} }
module = vlog_module_from_name(word); module = vlog_module_from_name(word);
} else { } else {
msg = xasprintf("no facility, level, or module \"%s\"", word); msg = xasprintf("no destination, level, or module \"%s\"",
word);
goto exit; goto exit;
} }
} }
if (facility == VLF_N_FACILITIES) { if (destination == VLF_N_DESTINATIONS) {
facility = VLF_ANY_FACILITY; destination = VLF_ANY_DESTINATION;
} }
if (level == VLL_N_LEVELS) { if (level == VLL_N_LEVELS) {
level = VLL_DBG; level = VLL_DBG;
} }
vlog_set_levels(module, facility, level); vlog_set_levels(module, destination, level);
} }
exit: exit:
@@ -480,7 +487,7 @@ vlog_set_verbosity(const char *arg)
ovs_fatal(0, "processing \"%s\": %s", arg, msg); ovs_fatal(0, "processing \"%s\": %s", arg, msg);
} }
} else { } else {
vlog_set_levels(NULL, VLF_ANY_FACILITY, VLL_DBG); vlog_set_levels(NULL, VLF_ANY_DESTINATION, VLL_DBG);
} }
} }
@@ -632,7 +639,7 @@ vlog_init(void)
} }
unixctl_command_register( unixctl_command_register(
"vlog/set", "{spec | PATTERN:facility:pattern}", "vlog/set", "{spec | PATTERN:destination: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, unixctl_command_register("vlog/list", "", 0, 0, vlog_unixctl_list,
NULL); NULL);
@@ -879,8 +886,9 @@ vlog_valist(const struct vlog_module *module, enum vlog_level level,
ovs_rwlock_rdlock(&pattern_rwlock); ovs_rwlock_rdlock(&pattern_rwlock);
if (log_to_console) { if (log_to_console) {
format_log_message(module, level, facilities[VLF_CONSOLE].pattern, format_log_message(module, level,
message, args, &s); destinations[VLF_CONSOLE].pattern, message,
args, &s);
ds_put_char(&s, '\n'); ds_put_char(&s, '\n');
fputs(ds_cstr(&s), stderr); fputs(ds_cstr(&s), stderr);
} }
@@ -890,7 +898,7 @@ vlog_valist(const struct vlog_module *module, enum vlog_level level,
char *save_ptr = NULL; char *save_ptr = NULL;
char *line; char *line;
format_log_message(module, level, facilities[VLF_SYSLOG].pattern, format_log_message(module, level, destinations[VLF_SYSLOG].pattern,
message, args, &s); message, args, &s);
for (line = strtok_r(s.string, "\n", &save_ptr); line; for (line = strtok_r(s.string, "\n", &save_ptr); line;
line = strtok_r(NULL, "\n", &save_ptr)) { line = strtok_r(NULL, "\n", &save_ptr)) {
@@ -907,7 +915,7 @@ vlog_valist(const struct vlog_module *module, enum vlog_level level,
} }
if (log_to_file) { if (log_to_file) {
format_log_message(module, level, facilities[VLF_FILE].pattern, format_log_message(module, level, destinations[VLF_FILE].pattern,
message, args, &s); message, args, &s);
ds_put_char(&s, '\n'); ds_put_char(&s, '\n');
@@ -944,7 +952,7 @@ vlog(const struct vlog_module *module, enum vlog_level level,
/* Logs 'message' to 'module' at maximum verbosity, then exits with a failure /* Logs 'message' to 'module' at maximum verbosity, then exits with a failure
* exit code. Always writes the message to stderr, even if the console * exit code. Always writes the message to stderr, even if the console
* facility is disabled. * destination is disabled.
* *
* Choose this function instead of vlog_abort_valist() if the daemon monitoring * Choose this function instead of vlog_abort_valist() if the daemon monitoring
* facility shouldn't automatically restart the current daemon. */ * facility shouldn't automatically restart the current daemon. */
@@ -964,7 +972,7 @@ vlog_fatal_valist(const struct vlog_module *module_,
/* Logs 'message' to 'module' at maximum verbosity, then exits with a failure /* Logs 'message' to 'module' at maximum verbosity, then exits with a failure
* exit code. Always writes the message to stderr, even if the console * exit code. Always writes the message to stderr, even if the console
* facility is disabled. * destination is disabled.
* *
* Choose this function instead of vlog_abort() if the daemon monitoring * Choose this function instead of vlog_abort() if the daemon monitoring
* facility shouldn't automatically restart the current daemon. */ * facility shouldn't automatically restart the current daemon. */
@@ -979,7 +987,7 @@ vlog_fatal(const struct vlog_module *module, const char *message, ...)
} }
/* Logs 'message' to 'module' at maximum verbosity, then calls abort(). Always /* Logs 'message' to 'module' at maximum verbosity, then calls abort(). Always
* writes the message to stderr, even if the console facility is disabled. * writes the message to stderr, even if the console destination is disabled.
* *
* Choose this function instead of vlog_fatal_valist() if the daemon monitoring * Choose this function instead of vlog_fatal_valist() if the daemon monitoring
* facility should automatically restart the current daemon. */ * facility should automatically restart the current daemon. */
@@ -998,7 +1006,7 @@ vlog_abort_valist(const struct vlog_module *module_,
} }
/* Logs 'message' to 'module' at maximum verbosity, then calls abort(). Always /* Logs 'message' to 'module' at maximum verbosity, then calls abort(). Always
* writes the message to stderr, even if the console facility is disabled. * writes the message to stderr, even if the console destination is disabled.
* *
* Choose this function instead of vlog_fatal() if the daemon monitoring * Choose this function instead of vlog_fatal() if the daemon monitoring
* facility should automatically restart the current daemon. */ * facility should automatically restart the current daemon. */

View File

@@ -7,7 +7,7 @@
.IQ "\fB\-\-verbose=\fR[\fIspec\fR] .IQ "\fB\-\-verbose=\fR[\fIspec\fR]
. .
Sets logging levels. Without any \fIspec\fR, sets the log level for Sets logging levels. Without any \fIspec\fR, sets the log level for
every module and facility to \fBdbg\fR. Otherwise, \fIspec\fR is a every module and destination to \fBdbg\fR. Otherwise, \fIspec\fR is a
list of words separated by spaces or commas or colons, up to one from list of words separated by spaces or commas or colons, up to one from
each category below: each category below:
. .
@@ -49,9 +49,9 @@ a word but has no effect.
Sets the maximum logging verbosity level, equivalent to Sets the maximum logging verbosity level, equivalent to
\fB\-\-verbose=dbg\fR. \fB\-\-verbose=dbg\fR.
. .
.IP "\fB\-vPATTERN:\fIfacility\fB:\fIpattern\fR" .IP "\fB\-vPATTERN:\fIdestination\fB:\fIpattern\fR"
.IQ "\fB\-\-verbose=PATTERN:\fIfacility\fB:\fIpattern\fR" .IQ "\fB\-\-verbose=PATTERN:\fIdestination\fB:\fIpattern\fR"
Sets the log pattern for \fIfacility\fR to \fIpattern\fR. Refer to Sets the log pattern for \fIdestination\fR to \fIpattern\fR. Refer to
\fBovs\-appctl\fR(8) for a description of the valid syntax for \fIpattern\fR. \fBovs\-appctl\fR(8) for a description of the valid syntax for \fIpattern\fR.
. .
.TP .TP

View File

@@ -26,7 +26,7 @@ import ovs.dirs
import ovs.unixctl import ovs.unixctl
import ovs.util import ovs.util
FACILITIES = {"console": "info", "file": "info", "syslog": "info"} DESTINATIONS = {"console": "info", "file": "info", "syslog": "info"}
PATTERNS = { PATTERNS = {
"console": "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c%T|%p|%m", "console": "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c%T|%p|%m",
"file": "%D{%Y-%m-%dT%H:%M:%S.###Z}|%05N|%c%T|%p|%m", "file": "%D{%Y-%m-%dT%H:%M:%S.###Z}|%05N|%c%T|%p|%m",
@@ -50,7 +50,7 @@ class Vlog:
__inited = False __inited = False
__msg_num = 0 __msg_num = 0
__start_time = 0 __start_time = 0
__mfl = {} # Module -> facility -> level __mfl = {} # Module -> destination -> level
__log_file = None __log_file = None
__file_handler = None __file_handler = None
__log_patterns = PATTERNS __log_patterns = PATTERNS
@@ -63,7 +63,7 @@ class Vlog:
assert not Vlog.__inited assert not Vlog.__inited
self.name = name.lower() self.name = name.lower()
if name not in Vlog.__mfl: if name not in Vlog.__mfl:
Vlog.__mfl[self.name] = FACILITIES.copy() Vlog.__mfl[self.name] = DESTINATIONS.copy()
def __log(self, level, message, **kwargs): def __log(self, level, message, **kwargs):
if not Vlog.__inited: if not Vlog.__inited:
@@ -79,8 +79,8 @@ class Vlog:
msg = self._build_message(message, f, level, msg_num) msg = self._build_message(message, f, level, msg_num)
logging.getLogger(f).log(level_num, msg, **kwargs) logging.getLogger(f).log(level_num, msg, **kwargs)
def _build_message(self, message, facility, level, msg_num): def _build_message(self, message, destination, level, msg_num):
pattern = self.__log_patterns[facility] pattern = self.__log_patterns[destination]
tmp = pattern tmp = pattern
tmp = self._format_time(tmp) tmp = self._format_time(tmp)
@@ -216,7 +216,7 @@ class Vlog:
Vlog.__start_time = datetime.datetime.utcnow() Vlog.__start_time = datetime.datetime.utcnow()
logging.raiseExceptions = False logging.raiseExceptions = False
Vlog.__log_file = log_file Vlog.__log_file = log_file
for f in FACILITIES: for f in DESTINATIONS:
logger = logging.getLogger(f) logger = logging.getLogger(f)
logger.setLevel(logging.DEBUG) logger.setLevel(logging.DEBUG)
@@ -241,17 +241,17 @@ class Vlog:
Vlog._unixctl_vlog_list, None) Vlog._unixctl_vlog_list, None)
@staticmethod @staticmethod
def set_level(module, facility, level): def set_level(module, destination, level):
""" Sets the log level of the 'module'-'facility' tuple to 'level'. """ Sets the log level of the 'module'-'destination' tuple to 'level'.
All three arguments are strings which are interpreted the same as All three arguments are strings which are interpreted the same as
arguments to the --verbose flag. Should be called after all Vlog arguments to the --verbose flag. Should be called after all Vlog
objects have already been created.""" objects have already been created."""
module = module.lower() module = module.lower()
facility = facility.lower() destination = destination.lower()
level = level.lower() level = level.lower()
if facility != "any" and facility not in FACILITIES: if destination != "any" and destination not in DESTINATIONS:
return return
if module != "any" and module not in Vlog.__mfl: if module != "any" and module not in Vlog.__mfl:
@@ -265,47 +265,47 @@ class Vlog:
else: else:
modules = [module] modules = [module]
if facility == "any": if destination == "any":
facilities = FACILITIES.keys() destinations = DESTINATIONS.keys()
else: else:
facilities = [facility] destinations = [destination]
for m in modules: for m in modules:
for f in facilities: for f in destinations:
Vlog.__mfl[m][f] = level Vlog.__mfl[m][f] = level
@staticmethod @staticmethod
def set_pattern(facility, pattern): def set_pattern(destination, pattern):
""" Sets the log pattern of the 'facility' to 'pattern' """ """ Sets the log pattern of the 'destination' to 'pattern' """
facility = facility.lower() destination = destination.lower()
Vlog.__log_patterns[facility] = pattern Vlog.__log_patterns[destination] = pattern
@staticmethod @staticmethod
def set_levels_from_string(s): def set_levels_from_string(s):
module = None module = None
level = None level = None
facility = None destination = None
words = re.split('[ :]', s) words = re.split('[ :]', s)
if words[0] == "pattern": if words[0] == "pattern":
try: try:
if words[1] in FACILITIES and words[2]: if words[1] in DESTINATIONS and words[2]:
segments = [words[i] for i in range(2, len(words))] segments = [words[i] for i in range(2, len(words))]
pattern = "".join(segments) pattern = "".join(segments)
Vlog.set_pattern(words[1], pattern) Vlog.set_pattern(words[1], pattern)
return return
else: else:
return "Facility %s does not exist" % words[1] return "Destination %s does not exist" % words[1]
except IndexError: except IndexError:
return "Please supply a valid pattern and facility" return "Please supply a valid pattern and destination"
for word in [w.lower() for w in words]: for word in [w.lower() for w in words]:
if word == "any": if word == "any":
pass pass
elif word in FACILITIES: elif word in DESTINATIONS:
if facility: if destination:
return "cannot specify multiple facilities" return "cannot specify multiple destinations"
facility = word destination = word
elif word in LEVELS: elif word in LEVELS:
if level: if level:
return "cannot specify multiple levels" return "cannot specify multiple levels"
@@ -315,9 +315,9 @@ class Vlog:
return "cannot specify multiple modules" return "cannot specify multiple modules"
module = word module = word
else: else:
return "no facility, level, or module \"%s\"" % word return "no destination, level, or module \"%s\"" % word
Vlog.set_level(module or "any", facility or "any", level or "any") Vlog.set_level(module or "any", destination or "any", level or "any")
@staticmethod @staticmethod
def get_levels(): def get_levels():

View File

@@ -45,7 +45,7 @@ test_reconnect_main(int argc OVS_UNUSED, char *argv[] OVS_UNUSED)
int old_time; int old_time;
char line[128]; char line[128];
vlog_set_levels(&VLM_reconnect, VLF_ANY_FACILITY, VLL_OFF); vlog_set_levels(&VLM_reconnect, VLF_ANY_DESTINATION, VLL_OFF);
now = 1000; now = 1000;
reconnect = reconnect_create(now); reconnect = reconnect_create(now);

View File

@@ -447,7 +447,7 @@ static void
test_vconn_main(int argc, char *argv[]) test_vconn_main(int argc, char *argv[])
{ {
set_program_name(argv[0]); set_program_name(argv[0]);
vlog_set_levels(NULL, VLF_ANY_FACILITY, VLL_EMER); vlog_set_levels(NULL, VLF_ANY_DESTINATION, VLL_EMER);
vlog_set_levels(NULL, VLF_CONSOLE, VLL_DBG); vlog_set_levels(NULL, VLF_CONSOLE, VLL_DBG);
fatal_ignore_sigpipe(); fatal_ignore_sigpipe();

View File

@@ -208,7 +208,7 @@ unixctl_server info info info
AT_CHECK([APPCTL -t test-unixctl.py vlog/set daemon:syslog:err]) AT_CHECK([APPCTL -t test-unixctl.py vlog/set daemon:syslog:err])
AT_CHECK([APPCTL -t test-unixctl.py vlog/set file:dbg]) AT_CHECK([APPCTL -t test-unixctl.py vlog/set file:dbg])
AT_CHECK([APPCTL -t test-unixctl.py vlog/set nonexistent], [0], AT_CHECK([APPCTL -t test-unixctl.py vlog/set nonexistent], [0],
[no facility, level, or module "nonexistent" [no destination, level, or module "nonexistent"
]) ])
AT_CHECK([APPCTL -t test-unixctl.py vlog/list], [0], [dnl AT_CHECK([APPCTL -t test-unixctl.py vlog/list], [0], [dnl
console syslog file console syslog file
@@ -225,10 +225,10 @@ unixctl_server info info dbg
]) ])
AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern], [0], AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern], [0],
[Please supply a valid pattern and facility [Please supply a valid pattern and destination
]) ])
AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern:nonexistent], [0], AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern:nonexistent], [0],
[Facility nonexistent does not exist [Destination nonexistent does not exist
]) ])
AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern:file:'I<3OVS|%m']) AT_CHECK([APPCTL -t test-unixctl.py vlog/set pattern:file:'I<3OVS|%m'])
AT_CHECK([APPCTL -t test-unixctl.py log patterntest]) AT_CHECK([APPCTL -t test-unixctl.py log patterntest])

View File

@@ -45,7 +45,7 @@ main(int argc OVS_UNUSED, char *argv[])
int error; int error;
set_program_name(argv[0]); set_program_name(argv[0]);
vlog_set_levels(NULL, VLF_ANY_FACILITY, VLL_DBG); vlog_set_levels(NULL, VLF_ANY_DESTINATION, VLL_DBG);
error = nl_sock_create(NETLINK_ROUTE, &sock); error = nl_sock_create(NETLINK_ROUTE, &sock);
if (error) { if (error) {

View File

@@ -84,7 +84,7 @@ 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. destination's log level to \fBoff\fR disables logging to that destination.
. .
.PP .PP
The following log levels, in order of descending severity, are The following log levels, in order of descending severity, are
@@ -114,7 +114,7 @@ Lists the known logging modules and their current levels.
. .
.IP "\fBvlog/set\fR [\fIspec\fR]" .IP "\fBvlog/set\fR [\fIspec\fR]"
Sets logging levels. Without any \fIspec\fR, sets the log level for Sets logging levels. Without any \fIspec\fR, sets the log level for
every module and facility to \fBdbg\fR. Otherwise, \fIspec\fR is a every module and destination to \fBdbg\fR. Otherwise, \fIspec\fR is a
list of words separated by spaces or commas or colons, up to one from list of words separated by spaces or commas or colons, up to one from
each category below: each category below:
. .
@@ -150,9 +150,9 @@ will not take place unless the target application was invoked with the
For compatibility with older versions of OVS, \fBany\fR is accepted as For compatibility with older versions of OVS, \fBany\fR is accepted as
a word but has no effect. a word but has no effect.
. .
.IP "\fBvlog/set PATTERN:\fIfacility\fB:\fIpattern\fR" .IP "\fBvlog/set PATTERN:\fIdestination\fB:\fIpattern\fR"
Sets the log pattern for \fIfacility\fR to \fIpattern\fR. Each time a Sets the log pattern for \fIdestination\fR to \fIpattern\fR. Each time a
message is logged to \fIfacility\fR, \fIpattern\fR determines the message is logged to \fIdestination\fR, \fIpattern\fR determines the
message's formatting. Most characters in \fIpattern\fR are copied message's formatting. Most characters in \fIpattern\fR are copied
literally to the log, but special escapes beginning with \fB%\fR are literally to the log, but special escapes beginning with \fB%\fR are
expanded as follows: expanded as follows:

View File

@@ -95,7 +95,7 @@ Common commands:\n\
vlog/set [SPEC]\n\ vlog/set [SPEC]\n\
Set log levels as detailed in SPEC, which may include:\n\ Set log levels as detailed in SPEC, which may include:\n\
A valid module name (all modules, by default)\n\ A valid module name (all modules, by default)\n\
'syslog', 'console', 'file' (all facilities, by default))\n\ 'syslog', 'console', 'file' (all destinations, by default))\n\
'off', 'emer', 'err', 'warn', 'info', or 'dbg' ('dbg', bydefault)\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\

View File

@@ -82,7 +82,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
set_program_name(argv[0]); set_program_name(argv[0]);
vlog_set_levels(NULL, VLF_ANY_FACILITY, VLL_EMER); vlog_set_levels(NULL, VLF_ANY_DESTINATION, VLL_EMER);
parse_options(argc, argv); parse_options(argc, argv);
run_command(argc - optind, argv + optind, get_all_commands()); run_command(argc - optind, argv + optind, get_all_commands());
return 0; return 0;

View File

@@ -464,7 +464,7 @@ print_result "complex completion check - ofproto/trace" "$TEST_RESULT"
# complex completion check - vlog/set # complex completion check - vlog/set
# vlog/set {spec | PATTERN:facility:pattern} # vlog/set {spec | PATTERN:destination:pattern}
# test non expandable arguments # test non expandable arguments
reset_globals reset_globals
@@ -473,7 +473,7 @@ for i in loop_once; do
# check the top level completion. # check the top level completion.
COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set TAB 2>&1)" COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set TAB 2>&1)"
TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')" TMP="$(get_argument_expansion "$COMP_OUTPUT" | sed -e 's/[ \t]*$//')"
EXPECT="$(generate_expect_completions "PATTERN:facility:pattern" "") EXPECT="$(generate_expect_completions "PATTERN:destination:pattern" "")
$(generate_expect_completions "spec" "")" $(generate_expect_completions "spec" "")"
if [ "$TMP" != "$EXPECT" ]; then if [ "$TMP" != "$EXPECT" ]; then
print_error "1" "$TMP" "$EXPECT" print_error "1" "$TMP" "$EXPECT"
@@ -494,7 +494,7 @@ $(generate_expect_completions "spec" "")"
COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set abcd TAB 2>&1)" COMP_OUTPUT="$(bash ovs-command-compgen.bash debug ovs-appctl vlog/set abcd TAB 2>&1)"
TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")" TMP="$(sed -e '/./,$!d' <<< "$COMP_OUTPUT")"
EXPECT="Command format: EXPECT="Command format:
vlog/set {spec | PATTERN:facility:pattern}" vlog/set {spec | PATTERN:destination:pattern}"
if [ "$TMP" != "$EXPECT" ]; then if [ "$TMP" != "$EXPECT" ]; then
print_error "3" "$TMP" "$EXPECT" print_error "3" "$TMP" "$EXPECT"
TEST_RESULT=fail TEST_RESULT=fail

View File

@@ -207,7 +207,7 @@ main(int argc, char *argv[])
set_program_name(argv[0]); set_program_name(argv[0]);
fatal_ignore_sigpipe(); fatal_ignore_sigpipe();
vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN); vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
vlog_set_levels(&VLM_reconnect, VLF_ANY_FACILITY, VLL_WARN); vlog_set_levels(&VLM_reconnect, VLF_ANY_DESTINATION, VLL_WARN);
ovsrec_init(); ovsrec_init();
/* Log our arguments. This is often valuable for debugging systems. */ /* Log our arguments. This is often valuable for debugging systems. */

View File

@@ -168,7 +168,7 @@ main(int argc, char *argv[])
set_program_name(argv[0]); set_program_name(argv[0]);
fatal_ignore_sigpipe(); fatal_ignore_sigpipe();
vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN); vlog_set_levels(NULL, VLF_CONSOLE, VLL_WARN);
vlog_set_levels(&VLM_reconnect, VLF_ANY_FACILITY, VLL_WARN); vlog_set_levels(&VLM_reconnect, VLF_ANY_DESTINATION, VLL_WARN);
vteprec_init(); vteprec_init();
/* Log our arguments. This is often valuable for debugging systems. */ /* Log our arguments. This is often valuable for debugging systems. */