Add timestamps to log file, fix? line terminations
r2105 | dcl | 2007-08-10 10:26:56 +1000 (Fri, 10 Aug 2007) | 2 lines
This commit is contained in:
32
servlog.c
32
servlog.c
@@ -221,7 +221,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* timestamp(void) {
|
||||||
|
static char ts[80];
|
||||||
|
int hh, mm, ss;
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
hh = (tv.tv_sec / 3600) % 24;
|
||||||
|
mm = (tv.tv_sec / 60) % 60;
|
||||||
|
ss = tv.tv_sec % 60;
|
||||||
|
snprintf(ts, 80, "%02d:%02d:%02d.%06d", hh, mm, ss, (int) tv.tv_usec);
|
||||||
|
return ts;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#define MAXLOG 10000
|
#define MAXLOG 10000
|
||||||
@@ -264,15 +277,14 @@
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void SICSLogWrite(char *pText, OutCode eOut)
|
void SICSLogWrite(char *pText, OutCode eOut)
|
||||||
{
|
{
|
||||||
char pFile[256];
|
|
||||||
char *pChar = NULL;
|
|
||||||
pCaptureEntry pCurrent;
|
pCaptureEntry pCurrent;
|
||||||
char pBueffel[256];
|
int text_len;
|
||||||
|
|
||||||
#ifdef NOLOG
|
#ifdef NOLOG
|
||||||
return ;
|
return ;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
text_len = strlen(pText);
|
||||||
/* do all captured */
|
/* do all captured */
|
||||||
pCurrent = pCapture;
|
pCurrent = pCapture;
|
||||||
while(pCurrent)
|
while(pCurrent)
|
||||||
@@ -280,6 +292,8 @@
|
|||||||
if( (pCurrent->iOut == eOut) || (pCurrent->iAllFlag == 1) )
|
if( (pCurrent->iOut == eOut) || (pCurrent->iAllFlag == 1) )
|
||||||
{
|
{
|
||||||
NETWrite(pCurrent->pCon->pSock,pText,strlen(pText));
|
NETWrite(pCurrent->pCon->pSock,pText,strlen(pText));
|
||||||
|
if (pText[text_len - 1] != '\n')
|
||||||
|
NETWrite(pCurrent->pCon->pSock, "\n", 1);
|
||||||
}
|
}
|
||||||
pCurrent = pCurrent->pNext;
|
pCurrent = pCurrent->pNext;
|
||||||
}
|
}
|
||||||
@@ -313,10 +327,15 @@
|
|||||||
|
|
||||||
if(1 == iLogUsable)
|
if(1 == iLogUsable)
|
||||||
{
|
{
|
||||||
fprintf(fLogFile,"%s\n",pText);
|
|
||||||
|
fprintf(fLogFile,"%s: ", timestamp());
|
||||||
|
fprintf(fLogFile,"%s", pText);
|
||||||
|
if (pText[text_len - 1] != '\n')
|
||||||
|
fprintf(fLogFile,"\n");
|
||||||
fflush(fLogFile);
|
fflush(fLogFile);
|
||||||
iLineCount++;
|
iLineCount++;
|
||||||
|
|
||||||
|
#if 0 /* Already done above */
|
||||||
/* do all captured as well */
|
/* do all captured as well */
|
||||||
pCurrent = pCapture;
|
pCurrent = pCapture;
|
||||||
while(pCurrent)
|
while(pCurrent)
|
||||||
@@ -324,8 +343,11 @@
|
|||||||
if( (pCurrent->iOut == eOut) || (pCurrent->iAllFlag == 1) )
|
if( (pCurrent->iOut == eOut) || (pCurrent->iAllFlag == 1) )
|
||||||
{
|
{
|
||||||
NETWrite(pCurrent->pCon->pSock,pText,strlen(pText));
|
NETWrite(pCurrent->pCon->pSock,pText,strlen(pText));
|
||||||
|
if (pText[text_len - 1] != '\n')
|
||||||
|
NETWrite(pCurrent->pCon->pSock, "\n", 1);
|
||||||
}
|
}
|
||||||
pCurrent = pCurrent->pNext;
|
pCurrent = pCurrent->pNext;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user