[ovs-dev] [PATCH v2] vlog: Change the default timestamp structure.
Gurucharan Shetty
gshetty at nicira.com
Fri Jan 27 23:55:17 UTC 2012
Change the default timestamp for console and file logs to
UTC in a format that satisfies timestamp requirements in RFC 5424.
Also, add the ability for ovs-appctl to log timestamps in UTC.
Bug #9052.
Signed-off-by: Gurucharan Shetty <gshetty at nicira.com>
---
NEWS | 3 +++
lib/dynamic-string.c | 12 +++++++++---
lib/dynamic-string.h | 2 +-
lib/vlog.c | 6 +++++-
lib/vlog.h | 4 ++--
utilities/ovs-appctl.8.in | 11 +++++++++--
6 files changed, 29 insertions(+), 9 deletions(-)
diff --git a/NEWS b/NEWS
index d7332f8..e015739 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ post-v1.5.0
- The default bond_mode changed from SLB to active-backup, to protect
unsuspecting users from the significant risks of SLB bonds (which are
documented in vswitchd/INTERNALS).
+ - 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.
v1.5.0 - xx xxx xxxx
diff --git a/lib/dynamic-string.c b/lib/dynamic-string.c
index dbb33a3..8c675d1 100644
--- a/lib/dynamic-string.c
+++ b/lib/dynamic-string.c
@@ -173,13 +173,19 @@ ds_put_printable(struct ds *ds, const char *s, size_t n)
}
}
+/* Writes the current time to 'string' based on 'template'.
+ * The current time is either localtime or UTC based on 'utc'. */
void
-ds_put_strftime(struct ds *ds, const char *template, const struct tm *tm)
+ds_put_strftime(struct ds *ds, const char *template, bool utc)
{
- if (!tm) {
- time_t now = time_wall();
+ const struct tm *tm;
+ time_t now = time_wall();
+ if (utc) {
+ tm = gmtime(&now);
+ } else {
tm = localtime(&now);
}
+
for (;;) {
size_t avail = ds->string ? ds->allocated - ds->length + 1 : 0;
size_t used = strftime(&ds->string[ds->length], avail, template, tm);
diff --git a/lib/dynamic-string.h b/lib/dynamic-string.h
index 2961a01..35a0357 100644
--- a/lib/dynamic-string.h
+++ b/lib/dynamic-string.h
@@ -49,7 +49,7 @@ void ds_put_format(struct ds *, const char *, ...) PRINTF_FORMAT(2, 3);
void ds_put_format_valist(struct ds *, const char *, va_list)
PRINTF_FORMAT(2, 0);
void ds_put_printable(struct ds *, const char *, size_t);
-void ds_put_strftime(struct ds *, const char *, const struct tm *)
+void ds_put_strftime(struct ds *, const char *, bool utc)
STRFTIME_FORMAT(2);
void ds_put_hex_dump(struct ds *ds, const void *buf_, size_t size,
uintptr_t ofs, bool ascii);
diff --git a/lib/vlog.c b/lib/vlog.c
index 0d7f4d1..7d9c061 100644
--- a/lib/vlog.c
+++ b/lib/vlog.c
@@ -610,7 +610,11 @@ format_log_message(const struct vlog_module *module, enum vlog_level level,
break;
case 'd':
p = fetch_braces(p, "%Y-%m-%d %H:%M:%S", tmp, sizeof tmp);
- ds_put_strftime(s, tmp, NULL);
+ ds_put_strftime(s, tmp, false);
+ break;
+ case 'D':
+ p = fetch_braces(p, "%Y-%m-%d %H:%M:%S", tmp, sizeof tmp);
+ ds_put_strftime(s, tmp, true);
break;
case 'm':
/* Format user-supplied log message and trim trailing new-lines. */
diff --git a/lib/vlog.h b/lib/vlog.h
index 6fa007b..5954d21 100644
--- a/lib/vlog.h
+++ b/lib/vlog.h
@@ -51,8 +51,8 @@ enum vlog_level vlog_get_level_val(const char *name);
/* Facilities that we can log to. */
#define VLOG_FACILITIES \
VLOG_FACILITY(SYSLOG, "%05N|%c|%p|%m") \
- VLOG_FACILITY(CONSOLE, "%d{%b %d %H:%M:%S}|%05N|%c|%p|%m") \
- VLOG_FACILITY(FILE, "%d{%b %d %H:%M:%S}|%05N|%c|%p|%m")
+ VLOG_FACILITY(CONSOLE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c|%p|%m") \
+ VLOG_FACILITY(FILE, "%D{%Y-%m-%dT%H:%M:%SZ}|%05N|%c|%p|%m")
enum vlog_facility {
#define VLOG_FACILITY(NAME, PATTERN) VLF_##NAME,
VLOG_FACILITIES
diff --git a/utilities/ovs-appctl.8.in b/utilities/ovs-appctl.8.in
index d851ea1..6a61732 100644
--- a/utilities/ovs-appctl.8.in
+++ b/utilities/ovs-appctl.8.in
@@ -139,6 +139,13 @@ The current date and time in ISO 8601 format (YYYY\-MM\-DD HH:MM:SS).
The current date and time in the specified \fIformat\fR, which takes
the same format as the \fItemplate\fR argument to \fBstrftime\fR(3).
.
+.IP \fB%D\fR
+The current UTC date and time in ISO 8601 format (YYYY\-MM\-DD HH:MM:SS).
+.
+.IP \fB%D{\fIformat\fB}\fR
+The current UTC date and time in the specified \fIformat\fR, which takes
+the same format as the \fItemplate\fR argument to \fBstrftime\fR(3).
+.
.IP \fB%m\fR
The message being logged.
.
@@ -184,8 +191,8 @@ width. (A field wider than \fIwidth\fR is not truncated to fit.)
.RE
.
.IP
-The default pattern for console and file output is \fB%d{%b %d
-%H:%M:%S}|%05N|%c|%p|%m\fR; for syslog output, \fB%05N|%c|%p|%m\fR.
+The default pattern for console and file output is \fB%D{%Y-%m-%dT
+%H:%M:%SZ}|%05N|%c|%p|%m\fR; for syslog output, \fB%05N|%c|%p|%m\fR.
.
.IP "\fBvlog/reopen\fR"
Causes the daemon to close and reopen its log file. (This
--
1.7.2.5
More information about the dev
mailing list