ip lib: Added shorter timestamp option
Added another timestamp format to look like more logging info:
[2014-12-22T22:36:50.489 ] 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>
This commit is contained in:
parent
3d0b7439df
commit
79aa79d058
|
|
@ -19,6 +19,7 @@ extern int show_raw;
|
||||||
extern int resolve_hosts;
|
extern int resolve_hosts;
|
||||||
extern int oneline;
|
extern int oneline;
|
||||||
extern int timestamp;
|
extern int timestamp;
|
||||||
|
extern int timestamp_short;
|
||||||
extern char * _SL_;
|
extern char * _SL_;
|
||||||
extern int max_flush_loops;
|
extern int max_flush_loops;
|
||||||
extern int batch_mode;
|
extern int batch_mode;
|
||||||
|
|
|
||||||
5
ip/ip.c
5
ip/ip.c
|
|
@ -53,7 +53,7 @@ static void usage(void)
|
||||||
" -f[amily] { inet | inet6 | ipx | dnet | bridge | link } |\n"
|
" -f[amily] { inet | inet6 | ipx | dnet | bridge | link } |\n"
|
||||||
" -4 | -6 | -I | -D | -B | -0 |\n"
|
" -4 | -6 | -I | -D | -B | -0 |\n"
|
||||||
" -l[oops] { maximum-addr-flush-attempts } |\n"
|
" -l[oops] { maximum-addr-flush-attempts } |\n"
|
||||||
" -o[neline] | -t[imestamp] | -b[atch] [filename] |\n"
|
" -o[neline] | -t[imestamp] | -t[short] | -b[atch] [filename] |\n"
|
||||||
" -rc[vbuf] [size]}\n");
|
" -rc[vbuf] [size]}\n");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|
@ -232,6 +232,9 @@ int main(int argc, char **argv)
|
||||||
++oneline;
|
++oneline;
|
||||||
} else if (matches(opt, "-timestamp") == 0) {
|
} else if (matches(opt, "-timestamp") == 0) {
|
||||||
++timestamp;
|
++timestamp;
|
||||||
|
} else if (matches(opt, "-tshort") == 0) {
|
||||||
|
++timestamp;
|
||||||
|
++timestamp_short;
|
||||||
#if 0
|
#if 0
|
||||||
} else if (matches(opt, "-numeric") == 0) {
|
} else if (matches(opt, "-numeric") == 0) {
|
||||||
rtnl_names_numeric++;
|
rtnl_names_numeric++;
|
||||||
|
|
|
||||||
22
lib/utils.c
22
lib/utils.c
|
|
@ -32,6 +32,8 @@
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
|
int timestamp_short = 0;
|
||||||
|
|
||||||
int get_integer(int *val, const char *arg, int base)
|
int get_integer(int *val, const char *arg, int base)
|
||||||
{
|
{
|
||||||
long res;
|
long res;
|
||||||
|
|
@ -772,14 +774,24 @@ __u8* hexstring_a2n(const char *str, __u8 *buf, int blen)
|
||||||
int print_timestamp(FILE *fp)
|
int print_timestamp(FILE *fp)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
char *tstr;
|
struct tm *tm;
|
||||||
|
|
||||||
memset(&tv, 0, sizeof(tv));
|
|
||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
|
tm = localtime(&tv.tv_sec);
|
||||||
|
|
||||||
|
if (timestamp_short) {
|
||||||
|
char tshort[40];
|
||||||
|
|
||||||
|
strftime(tshort, sizeof(tshort), "%Y-%m-%dT%H:%M:%S", tm);
|
||||||
|
fprintf(fp, "[%s.%06ld] ", tshort, tv.tv_usec);
|
||||||
|
} else {
|
||||||
|
char *tstr = asctime(tm);
|
||||||
|
|
||||||
|
tstr[strlen(tstr)-1] = 0;
|
||||||
|
fprintf(fp, "Timestamp: %s %ld usec\n",
|
||||||
|
tstr, tv.tv_usec);
|
||||||
|
}
|
||||||
|
|
||||||
tstr = asctime(localtime(&tv.tv_sec));
|
|
||||||
tstr[strlen(tstr)-1] = 0;
|
|
||||||
fprintf(fp, "Timestamp: %s %ld usec\n", tstr, (long)tv.tv_usec);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,19 @@ ip-monitor, rtmon \- state monitoring
|
||||||
]
|
]
|
||||||
.sp
|
.sp
|
||||||
|
|
||||||
|
.SH OPTIONS
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BR "\-t" , " \-timestamp"
|
||||||
|
Prints timestamp before the event message on the separated line in format:
|
||||||
|
Timestamp: <Day> <Month> <DD> <hh:mm:ss> <YYYY> <usecs> usec
|
||||||
|
<EVENT>
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.BR "\-ts" , " \-tshort"
|
||||||
|
Prints short timestamp before the event message on the same line in format:
|
||||||
|
[<YYYY>-<MM>-<DD>T<hh:mm:ss>.<ms>] <EVENT>
|
||||||
|
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
The
|
The
|
||||||
.B ip
|
.B ip
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue