mirror of
https://github.com/openvswitch/ovs
synced 2025-10-29 15:28:56 +00:00
vlog: Change the default timestamp structure.
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@nicira.com>
This commit is contained in:
3
NEWS
3
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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user