From c2c62a75a7776046ee237a3243f3693e747e36a6 Mon Sep 17 00:00:00 2001 From: leslie Date: Thu, 21 May 2009 20:11:22 +0800 Subject: [PATCH] add microprecision timestamp to logging --- log.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/log.c b/log.c index 6176256..1d99450 100644 --- a/log.c +++ b/log.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -89,9 +90,11 @@ bool cLogging::GetHeader(int c, struct LogHeader *lh) const struct LogModule *lm=GetModule(c); if(lm) { if(!logcfg.noTimestamp) { - time_t tt=time(0); + struct timeval t; + gettimeofday(&t,NULL); struct tm tm_r; - strftime(lh->stamp,sizeof(lh->stamp),"%b %e %T",localtime_r(&tt,&tm_r)); + int q=strftime(lh->stamp,sizeof(lh->stamp),"%b %e %T",localtime_r(&t.tv_sec,&tm_r)); + snprintf(lh->stamp+q,sizeof(lh->stamp)-q,".%03u",(unsigned int)(t.tv_usec/1000)); } else lh->stamp[0]=0; int i, o=LOPT(c)&~LMOD_ENABLE; -- 2.39.5