[Openvpn-devel] Change timestamps in file-based logging to ISO 8601 time format.

Message ID 20200620172303.15010-1-gert@greenie.muc.de
State Accepted
Headers show
Series [Openvpn-devel] Change timestamps in file-based logging to ISO 8601 time format. | expand

Commit Message

Gert Doering June 20, 2020, 7:23 a.m. UTC
Replace existing ctime() output which is hard to sort and compare
with ISO 8601 / RFC 3399 "YYYY-MM-DD hh:mm:dd" format for file-based
logging (stderr or --log file).

RFC 3399 5.6 permits use of a space for full-date-full-time separation,
which is used to enhance readability.

Sylog or --machine-readable-timestamps are not affected.

Trac: #719

Signed-off-by: Gert Doering <gert@greenie.muc.de>
---
 src/openvpn/otime.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Arne Schwabe June 20, 2020, 8:35 a.m. UTC | #1
Am 20.06.20 um 19:23 schrieb Gert Doering:
> Replace existing ctime() output which is hard to sort and compare
> with ISO 8601 / RFC 3399 "YYYY-MM-DD hh:mm:dd" format for file-based
> logging (stderr or --log file).
> 
> RFC 3399 5.6 permits use of a space for full-date-full-time separation,
> which is used to enhance readability.
> 
> Sylog or --machine-readable-timestamps are not affected.

you mean machine-readable-output?

> Signed-off-by: Gert Doering <gert@greenie.muc.de>
> ---
>  src/openvpn/otime.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/src/openvpn/otime.c b/src/openvpn/otime.c
> index 759a7fb5..28683459 100644
> --- a/src/openvpn/otime.c
> +++ b/src/openvpn/otime.c
> @@ -127,8 +127,11 @@ time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc)
>      }
>  
>      t = tv.tv_sec;
> -    buf_printf(&out, "%s", ctime(&t));
> -    buf_rmtail(&out, '\n');
> +    struct tm * tm = localtime(&t);

should be *tm

> +
> +    buf_printf(&out, "%04d-%02d-%02d %02d:%02d:%02d",
> +                tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
> +                tm->tm_hour, tm->tm_min, tm->tm_sec);
>  
>      if (show_usec && tv.tv_usec)
>      {
> 


ACKed-By: Arne Schwabe <arne@rfc2549.org>
Gert Doering June 20, 2020, 10:55 a.m. UTC | #2
Patch has been applied to the master branch.

I have corrected the commit message (yes, --machine-readable-output) and
the "*tm" whitespacing.

commit ff063b6f19e035da56fbf49c891e6376543b391d
Author: Gert Doering
Date:   Sat Jun 20 19:23:03 2020 +0200

     Change timestamps in file-based logging to ISO 8601 time format.

     Signed-off-by: Gert Doering <gert@greenie.muc.de>
     Acked-by: Arne Schwabe <arne@rfc2549.org>
     Message-Id: <20200620172303.15010-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg20040.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/otime.c b/src/openvpn/otime.c
index 759a7fb5..28683459 100644
--- a/src/openvpn/otime.c
+++ b/src/openvpn/otime.c
@@ -127,8 +127,11 @@  time_string(time_t t, int usec, bool show_usec, struct gc_arena *gc)
     }
 
     t = tv.tv_sec;
-    buf_printf(&out, "%s", ctime(&t));
-    buf_rmtail(&out, '\n');
+    struct tm * tm = localtime(&t);
+
+    buf_printf(&out, "%04d-%02d-%02d %02d:%02d:%02d",
+                tm->tm_year+1900, tm->tm_mon+1, tm->tm_mday,
+                tm->tm_hour, tm->tm_min, tm->tm_sec);
 
     if (show_usec && tv.tv_usec)
     {