From: leslie Date: Thu, 21 May 2009 12:11:22 +0000 (+0800) Subject: add microprecision timestamp to logging X-Git-Tag: 0.9.2~30 X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=c2c62a75a7776046ee237a3243f3693e747e36a6;p=sasc-ng.git add microprecision timestamp to logging --- 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;