[ovs-dev] [PATCH v1] vlog.c: Avoid duplicating log message in rsyslog if enabling syslog-target
Michael Hu
humichael at vmware.com
Sat Apr 11 01:55:23 UTC 2015
From: Michael Hu <humichael at nicira.com>
vlog.c: Avoid duplicating log message in rsyslog if enabling syslog-target
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 <humichael at nicira.com>
---
v1: changed man page too.
---
include/openvswitch/vlog.h | 6 ++++--
lib/vlog.c | 31 +++++++++++++++----------------
lib/vlog.man | 2 +-
3 files changed, 20 insertions(+), 19 deletions(-)
diff --git a/include/openvswitch/vlog.h b/include/openvswitch/vlog.h
index 680fba4..740144a 100644
--- a/include/openvswitch/vlog.h
+++ b/include/openvswitch/vlog.h
@@ -62,8 +62,10 @@ 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(RSYSLOG, "<%B>1 %D{%Y-%m-%dT%H:%M:%S.###Z} " \
+ "%E %A %P %c \xef\xbb\xbf%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")
enum vlog_destination {
#define VLOG_DESTINATION(NAME, PATTERN) VLF_##NAME,
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 at 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.
More information about the dev
mailing list