diff --git a/servlog.c b/servlog.c index f839207e..12654af9 100644 --- a/servlog.c +++ b/servlog.c @@ -53,6 +53,7 @@ #include #include #include +#include #include "ifile.h" #include "conman.h" #include "servlog.h" @@ -223,11 +224,14 @@ return 1; } -static const char* timestamp(void) { +static const char* timestamp(struct timeval *tp) { static char ts[80]; int hh, mm, ss; struct timeval tv; - gettimeofday(&tv, NULL); + if (tp) + tv = *tp; + else + gettimeofday(&tv, NULL); hh = (tv.tv_sec / 3600) % 24; mm = (tv.tv_sec / 60) % 60; ss = tv.tv_sec % 60; @@ -275,7 +279,7 @@ static const char* timestamp(void) { } /*---------------------------------------------------------------------------*/ - void SICSLogWrite(char *pText, OutCode eOut) + void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp) { pCaptureEntry pCurrent; int text_len; @@ -314,7 +318,7 @@ static const char* timestamp(void) { /* switch file if too many lines */ if(iLineCount >= MAXLOG) { - fprintf(fLogFile,"%s: <<>>\n", timestamp()); + fprintf(fLogFile,"%s: <<>>\n", timestamp(NULL)); fclose(fLogFile); fLogFile = NULL; iFile++; @@ -330,8 +334,8 @@ static const char* timestamp(void) { { if (iLineCount == 0) - fprintf(fLogFile,"%s: <<>>\n", timestamp()); - fprintf(fLogFile,"%s: ", timestamp()); + fprintf(fLogFile,"%s: <<>>\n", timestamp(NULL)); + fprintf(fLogFile,"%s: ", timestamp(tp)); fprintf(fLogFile,"%s", pText); if (text_len < 1 || pText[text_len - 1] != '\n') fprintf(fLogFile,"\n"); @@ -354,3 +358,7 @@ static const char* timestamp(void) { #endif } } + + void SICSLogWrite(char *pText, OutCode eOut) { + SICSLogWriteTime(pText, eOut, NULL); + } diff --git a/servlog.h b/servlog.h index dfb3cbb7..2b345d0b 100644 --- a/servlog.h +++ b/servlog.h @@ -16,6 +16,7 @@ #define SICSLOG #include "Scommon.h" void SICSLogWrite(char *ptext, OutCode eOut ); + void SICSLogWriteTime(char *ptext, OutCode eOut, struct timeval *tp ); int KillCapture(SConnection *pCon); int LogCapture(SConnection *pCon, SicsInterp *pInter, void *pData,