From: Michael Hu <humich...@nicira.com> Currently if --syslog-target=127.0.0.1:514 is enabled, syslog would have duplicated log messages. The fix will not call syslog() if already having syslog_fd indicating message is sent through udp.
Signed-off-by: Michael Hu <humich...@nicira.com> --- v1-v2: put RSYSLOG last in DESTINATION as ovs initialized the first three facilities. --- include/openvswitch/vlog.h | 8 +++++--- lib/vlog.c | 31 +++++++++++++++---------------- lib/vlog.man | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/include/openvswitch/vlog.h b/include/openvswitch/vlog.h index 680fba4..3ca879a 100644 --- a/include/openvswitch/vlog.h +++ b/include/openvswitch/vlog.h @@ -62,9 +62,11 @@ enum vlog_level vlog_get_level_val(const char *name); /* Destinations that we can log to. */ #define VLOG_DESTINATIONS \ - VLOG_DESTINATION(SYSLOG, "ovs|%05N|%c%T|%p|%m") \ - VLOG_DESTINATION(CONSOLE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c%T|%p|%m") \ - VLOG_DESTINATION(FILE, "%D{%Y-%m-%dT%H:%M:%S.###Z}|%05N|%c%T|%p|%m") + VLOG_DESTINATION(SYSLOG, "ovs|%05N|%c%T|%p|%m") \ + VLOG_DESTINATION(CONSOLE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c%T|%p|%m") \ + VLOG_DESTINATION(FILE, "%D{%Y-%m-%dT%H:%M:%S.###Z}|%05N|%c%T|%p|%m") \ + VLOG_DESTINATION(RSYSLOG, "<%B>1 %D{%Y-%m-%dT%H:%M:%S.###Z} " \ + "%E %A %P %c \xef\xbb\xbf%m") enum vlog_destination { #define VLOG_DESTINATION(NAME, PATTERN) VLF_##NAME, VLOG_DESTINATIONS diff --git a/lib/vlog.c b/lib/vlog.c index da7a307..d1265a8 100644 --- a/lib/vlog.c +++ b/lib/vlog.c @@ -960,26 +960,25 @@ vlog_valist(const struct vlog_module *module, enum vlog_level level, } if (log_to_syslog) { - int syslog_level = syslog_levels[level]; - char *save_ptr = NULL; - char *line; - int facility; - - format_log_message(module, level, destinations[VLF_SYSLOG].pattern, - message, args, &s); - for (line = strtok_r(s.string, "\n", &save_ptr); line; - line = strtok_r(NULL, "\n", &save_ptr)) { - atomic_read_explicit(&log_facility, &facility, - memory_order_relaxed); - syslog(syslog_level|facility, "%s", line); - } - if (syslog_fd >= 0) { format_log_message(module, level, - "<%B>1 %D{%Y-%m-%dT%H:%M:%S.###Z} " - "%E %A %P %c - \xef\xbb\xbf%m", + destinations[VLF_RSYSLOG].pattern, message, args, &s); send_to_syslog_fd(ds_cstr(&s), s.length); + } else { + int syslog_level = syslog_levels[level]; + char *save_ptr = NULL; + char *line; + int facility; + + format_log_message(module, level, destinations[VLF_SYSLOG].pattern, + message, args, &s); + for (line = strtok_r(s.string, "\n", &save_ptr); line; + line = strtok_r(NULL, "\n", &save_ptr)) { + atomic_read_explicit(&log_facility, &facility, + memory_order_relaxed); + syslog(syslog_level|facility, "%s", line); + } } } diff --git a/lib/vlog.man b/lib/vlog.man index 5ee34f8..441c1f4 100644 --- a/lib/vlog.man +++ b/lib/vlog.man @@ -72,6 +72,6 @@ used as the exact name for the log file. The default log file name used if \fIfile\fR is omitted is \fB@LOGDIR@/\*(PN.log\fR. . .IP "\fB\-\-syslog\-target=\fIhost\fB:\fIport\fR" -Send syslog messages to UDP \fIport\fR on \fIhost\fR, in addition to +Send syslog messages to UDP \fIport\fR on \fIhost\fR, instead of the system syslog. The \fIhost\fR must be a numerical IP address, not a hostname. -- 1.9.1 _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev