Added SICSLogWriteTime to allow timestamp to be supplied for deferred logging

r2366 | dcl | 2008-02-21 15:02:15 +1100 (Thu, 21 Feb 2008) | 2 lines
This commit is contained in:
Douglas Clowes
2008-02-21 15:02:15 +11:00
parent c97b23fbcb
commit 2d58f48a88
2 changed files with 15 additions and 6 deletions

View File

@@ -53,6 +53,7 @@
#include <assert.h>
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include "ifile.h"
#include "conman.h"
#include "servlog.h"
@@ -223,10 +224,13 @@
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;
if (tp)
tv = *tp;
else
gettimeofday(&tv, NULL);
hh = (tv.tv_sec / 3600) % 24;
mm = (tv.tv_sec / 60) % 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: <<<close logfile>>>\n", timestamp());
fprintf(fLogFile,"%s: <<<close logfile>>>\n", timestamp(NULL));
fclose(fLogFile);
fLogFile = NULL;
iFile++;
@@ -330,8 +334,8 @@ static const char* timestamp(void) {
{
if (iLineCount == 0)
fprintf(fLogFile,"%s: <<<open logfile>>>\n", timestamp());
fprintf(fLogFile,"%s: ", timestamp());
fprintf(fLogFile,"%s: <<<open logfile>>>\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);
}

View File

@@ -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,