netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] ip lib: Change timestamp to be shorter and on the same line
@ 2014-09-16  9:58 Vadim Kochan
  2014-09-17  2:38 ` Stephen Hemminger
  0 siblings, 1 reply; 4+ messages in thread
From: Vadim Kochan @ 2014-09-16  9:58 UTC (permalink / raw)
  To: netdev; +Cc: Vadim Kochan

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

Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
---
 lib/utils.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/lib/utils.c b/lib/utils.c
index dc21567..03092ba 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -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;
 }
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ip lib: Change timestamp to be shorter and on the same line
  2014-09-16  9:58 [PATCH iproute2] ip lib: Change timestamp to be shorter and on the same line Vadim Kochan
@ 2014-09-17  2:38 ` Stephen Hemminger
  2014-09-17  6:06   ` Vadim Kochan
  0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2014-09-17  2:38 UTC (permalink / raw)
  To: Vadim Kochan; +Cc: netdev

On Tue, 16 Sep 2014 12:58:06 +0300
Vadim Kochan <vadim4j@gmail.com> 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_fast state UP group default
>     link/ether 3c:97:0e:a3:86:2e brd ff:ff:ff:ff:ff:ff
> 
> Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
> ---
>  lib/utils.c | 7 +++----
>  1 file changed, 3 insertions(+), 4 deletions(-)
> 
> diff --git a/lib/utils.c b/lib/utils.c
> index dc21567..03092ba 100644
> --- a/lib/utils.c
> +++ b/lib/utils.c
> @@ -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;
>  }
>  

I am loath to change the output format since people write scripts parsing
output. Maybe add a new flag option to choose format?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ip lib: Change timestamp to be shorter and on the same line
  2014-09-17  2:38 ` Stephen Hemminger
@ 2014-09-17  6:06   ` Vadim Kochan
  2014-10-10 11:27     ` Vadim Kochan
  0 siblings, 1 reply; 4+ messages in thread
From: Vadim Kochan @ 2014-09-17  6:06 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev@vger.kernel.org

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.

On Wed, Sep 17, 2014 at 5:38 AM, Stephen Hemminger
<stephen@networkplumber.org> wrote:
> On Tue, 16 Sep 2014 12:58:06 +0300
> Vadim Kochan <vadim4j@gmail.com> 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_fast state UP group default
>>     link/ether 3c:97:0e:a3:86:2e brd ff:ff:ff:ff:ff:ff
>>
>> Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
>> ---
>>  lib/utils.c | 7 +++----
>>  1 file changed, 3 insertions(+), 4 deletions(-)
>>
>> diff --git a/lib/utils.c b/lib/utils.c
>> index dc21567..03092ba 100644
>> --- a/lib/utils.c
>> +++ b/lib/utils.c
>> @@ -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;
>>  }
>>
>
> I am loath to change the output format since people write scripts parsing
> output. Maybe add a new flag option to choose format?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH iproute2] ip lib: Change timestamp to be shorter and on the same line
  2014-09-17  6:06   ` Vadim Kochan
@ 2014-10-10 11:27     ` Vadim Kochan
  0 siblings, 0 replies; 4+ messages in thread
From: Vadim Kochan @ 2014-10-10 11:27 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev@vger.kernel.org

Hi,

I was thinking about new option but can't find out nothing better than
"-tshort" matched option.

Regards,

On Wed, Sep 17, 2014 at 9:06 AM, Vadim Kochan <vadim4j@gmail.com> wrote:
> 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.
>
> On Wed, Sep 17, 2014 at 5:38 AM, Stephen Hemminger
> <stephen@networkplumber.org> wrote:
>> On Tue, 16 Sep 2014 12:58:06 +0300
>> Vadim Kochan <vadim4j@gmail.com> 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_fast state UP group default
>>>     link/ether 3c:97:0e:a3:86:2e brd ff:ff:ff:ff:ff:ff
>>>
>>> Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
>>> ---
>>>  lib/utils.c | 7 +++----
>>>  1 file changed, 3 insertions(+), 4 deletions(-)
>>>
>>> diff --git a/lib/utils.c b/lib/utils.c
>>> index dc21567..03092ba 100644
>>> --- a/lib/utils.c
>>> +++ b/lib/utils.c
>>> @@ -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;
>>>  }
>>>
>>
>> I am loath to change the output format since people write scripts parsing
>> output. Maybe add a new flag option to choose format?

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-10-10 11:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-16  9:58 [PATCH iproute2] ip lib: Change timestamp to be shorter and on the same line Vadim Kochan
2014-09-17  2:38 ` Stephen Hemminger
2014-09-17  6:06   ` Vadim Kochan
2014-10-10 11:27     ` Vadim Kochan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).