ip lib: Change timestamp to be shorter and on the same line
Subsystems (3)
PATCH 1/1 ip lib: Change timestamp to be shorter and on the same line
Changed timestamp format to look like more logging info:
[Sep 01 20:56:11.853146]2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default
link/ether 3c:97:0e:a3:86:2e brd ff:ff:ff:ff:ff:ff
--- lib/utils.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
lib/utils.c +3 -4
@@ -772,14 +772,13 @@ __u8* hexstring_a2n(const char *str, __u8 *buf, int blen)int print_timestamp (FILE *fp) {struct timeval tv; -char *tstr; +char tstr[40 ] = {};memset (&tv,0 ,sizeof (tv));gettimeofday (&tv,NULL ); - tstr =asctime (localtime (&tv.tv_sec)); - tstr[strlen (tstr)-1 ] =0 ; -fprintf (fp,"Timestamp: %s %ld usec\n" , tstr, (long )tv.tv_usec); +strftime (tstr,sizeof (tstr),"%b %d %H:%M:%S" ,localtime (&tv.tv_sec)); +fprintf (fp,"[%s.%ld]" , tstr, (long )tv.tv_usec);return 0 ; }
Signature · 1 line
2.1.0
Quoted 22 lines · On Tue, 16 Sep 2014 12:58:06 +0300 Vadim Kochan <[email protected]> wrote:
Changed timestamp format to look like more logging info:
[Sep 01 20:56:11.853146]2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_faststate UP group defaultlink/ether 3c:97:0e:a3:86:2e brd ff:ff:ff:ff:ff:ffSigned-off-by Vadim Kochan <[email protected]>--- lib/utils.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)lib/utils.c +1
-1@@ -772,14 +772,13 @@ __u8* hexstring_a2n(const char *str, __u8 *buf, int blen)int print_timestamp (FILE *fp) {struct timeval tv; -char *tstr; +char tstr[40 ] = {};memset (&tv,0 ,sizeof (tv));
lib/utils.c __u8* hexstring_a2n(const char *str, __u8 *buf, int blen) · line 784
Quoted 10 lines
lib/utils.c +2
-3gettimeofday (&tv,NULL ); - tstr =asctime (localtime (&tv.tv_sec)); - tstr[strlen (tstr)-1 ] =0 ; -fprintf (fp,"Timestamp: %s %ld usec\n" , tstr, (long )tv.tv_usec); +strftime (tstr,sizeof (tstr),"%b %d %H:%M:%S" ,localtime (&tv.tv_sec)); +fprintf (fp,"[%s.%ld]" , tstr, (long )tv.tv_usec);return 0 ; }
I am loath to change the output format since people write scripts parsing output. Maybe add a new flag option to choose format?
Sure, I can add new option, currently timestamp is printed on separated line so this solution I think can be easier to parse when it will be on the same line as message,
and easier to detect to which message timestamp belongs.
Quoted 38 lines · Stephen Hemminger
Quoted 22 lines · On Tue, 16 Sep 2014 12:58:06 +0300 Vadim Kochan <[email protected]> wrote:
Changed timestamp format to look like more logging info:
[Sep 01 20:56:11.853146]2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_faststate UP group defaultlink/ether 3c:97:0e:a3:86:2e brd ff:ff:ff:ff:ff:ffSigned-off-by Vadim Kochan <[email protected]>--- lib/utils.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)lib/utils.c +1
-1@@ -772,14 +772,13 @@ __u8* hexstring_a2n(const char *str, __u8 *buf, int blen)int print_timestamp (FILE *fp) {struct timeval tv; -char *tstr; +char tstr[40 ] = {};memset (&tv,0 ,sizeof (tv));lib/utils.c __u8* hexstring_a2n(const char *str, __u8 *buf, int blen) · line 784
Quoted 10 lines
lib/utils.c +2
-3gettimeofday (&tv,NULL ); - tstr =asctime (localtime (&tv.tv_sec)); - tstr[strlen (tstr)-1 ] =0 ; -fprintf (fp,"Timestamp: %s %ld usec\n" , tstr, (long )tv.tv_usec); +strftime (tstr,sizeof (tstr),"%b %d %H:%M:%S" ,localtime (&tv.tv_sec)); +fprintf (fp,"[%s.%ld]" , tstr, (long )tv.tv_usec);return 0 ; }I am loath to change the output format since people write scripts parsing output. Maybe add a new flag option to choose format?
Hi,
I was thinking about new option but can't find out nothing better than "-tshort" matched option.
Regards,
Quoted 45 lines · Vadim Kochan
Sure, I can add new option, currently timestamp is printed on separated line so this solution I think can be easier to parse when it will be on the same line as message,
and easier to detect to which message timestamp belongs.Quoted 38 lines · Stephen Hemminger
Quoted 22 lines · On Tue, 16 Sep 2014 12:58:06 +0300 Vadim Kochan <[email protected]> wrote:
Changed timestamp format to look like more logging info:
[Sep 01 20:56:11.853146]2: enp0s25: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc
pfifo_faststate UP group defaultlink/ether 3c:97:0e:a3:86:2e brd ff:ff:ff:ff:ff:ffSigned-off-by Vadim Kochan <[email protected]>--- lib/utils.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)lib/utils.c +1
-1@@ -772,14 +772,13 @@ __u8* hexstring_a2n(const char *str, __u8 *buf, int blen)int print_timestamp (FILE *fp) {struct timeval tv; -char *tstr; +char tstr[40 ] = {};memset (&tv,0 ,sizeof (tv));lib/utils.c __u8* hexstring_a2n(const char *str, __u8 *buf, int blen) · line 784
Quoted 10 lines
lib/utils.c +2
-3gettimeofday (&tv,NULL ); - tstr =asctime (localtime (&tv.tv_sec)); - tstr[strlen (tstr)-1 ] =0 ; -fprintf (fp,"Timestamp: %s %ld usec\n" , tstr, (long )tv.tv_usec); +strftime (tstr,sizeof (tstr),"%b %d %H:%M:%S" ,localtime (&tv.tv_sec)); +fprintf (fp,"[%s.%ld]" , tstr, (long )tv.tv_usec);return 0 ; }I am loath to change the output format since people write scripts parsing output. Maybe add a new flag option to choose format?