log: print timestamps with millisecond precision
this allows easier time measurements for benchmarks.
This commit is contained in:
parent
10494cab8c
commit
f55c46eb39
@ -108,7 +108,7 @@ void set_log_level (int level)
|
|||||||
void log_message (int level, const char *fmt, ...)
|
void log_message (int level, const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
time_t nowtime;
|
struct timespec nowtime;
|
||||||
|
|
||||||
char time_string[TIME_LENGTH];
|
char time_string[TIME_LENGTH];
|
||||||
char str[STRING_LENGTH];
|
char str[STRING_LENGTH];
|
||||||
@ -174,13 +174,14 @@ void log_message (int level, const char *fmt, ...)
|
|||||||
} else {
|
} else {
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
nowtime = time (NULL);
|
clock_gettime(CLOCK_REALTIME, &nowtime);
|
||||||
/* Format is month day hour:minute:second (24 time) */
|
/* Format is month day hour:minute:second (24 time) */
|
||||||
strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S",
|
strftime (time_string, TIME_LENGTH, "%b %d %H:%M:%S",
|
||||||
localtime (&nowtime));
|
localtime (&nowtime.tv_sec));
|
||||||
|
|
||||||
snprintf (str, STRING_LENGTH, "%-9s %s [%ld]: ",
|
snprintf (str, STRING_LENGTH, "%-9s %s.%03u [%ld]: ",
|
||||||
syslog_level[level], time_string,
|
syslog_level[level], time_string,
|
||||||
|
nowtime.tv_nsec/1000000u,
|
||||||
(long int) getpid ());
|
(long int) getpid ());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user