mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
src: replace gmtime_r/localtime_r/strftime with GDateTime
gmtime_r/localtime_r are mostly used in combination with strftime to format timestamps in libvirt. This can all be replaced with GDateTime resulting in simpler code that is also more portable. There is some boundary condition problem in parsing POSIX timezone offsets in GLib which tickles our test suite. The test suite is hacked to avoid the problem. The upsteam GLib bug report is https://gitlab.gnome.org/GNOME/glib/issues/1999 Reviewed-by: Pavel Hrdina <phrdina@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
16
tools/vsh.c
16
tools/vsh.c
@@ -2182,8 +2182,8 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
|
||||
char *str = NULL;
|
||||
size_t len;
|
||||
const char *lvl = "";
|
||||
time_t stTime;
|
||||
struct tm stTm;
|
||||
g_autoptr(GDateTime) now = g_date_time_new_now_local();
|
||||
g_autofree gchar *nowstr = NULL;
|
||||
|
||||
if (ctl->log_fd == -1)
|
||||
return;
|
||||
@@ -2193,15 +2193,9 @@ vshOutputLogFile(vshControl *ctl, int log_level, const char *msg_format,
|
||||
*
|
||||
* [YYYY.MM.DD HH:MM:SS SIGNATURE PID] LOG_LEVEL message
|
||||
*/
|
||||
time(&stTime);
|
||||
localtime_r(&stTime, &stTm);
|
||||
virBufferAsprintf(&buf, "[%d.%02d.%02d %02d:%02d:%02d %s %d] ",
|
||||
(1900 + stTm.tm_year),
|
||||
(1 + stTm.tm_mon),
|
||||
stTm.tm_mday,
|
||||
stTm.tm_hour,
|
||||
stTm.tm_min,
|
||||
stTm.tm_sec,
|
||||
nowstr = g_date_time_format(now, "%Y.%m.%d %H:%M:%S");
|
||||
virBufferAsprintf(&buf, "[%s %s %d] ",
|
||||
nowstr,
|
||||
ctl->progname,
|
||||
(int) getpid());
|
||||
switch (log_level) {
|
||||
|
||||
Reference in New Issue
Block a user