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:
30
servlog.c
30
servlog.c
@@ -223,6 +223,19 @@
|
||||
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 MAXFILES 20
|
||||
@@ -264,15 +277,14 @@
|
||||
/*---------------------------------------------------------------------------*/
|
||||
void SICSLogWrite(char *pText, OutCode eOut)
|
||||
{
|
||||
char pFile[256];
|
||||
char *pChar = NULL;
|
||||
pCaptureEntry pCurrent;
|
||||
char pBueffel[256];
|
||||
int text_len;
|
||||
|
||||
#ifdef NOLOG
|
||||
return ;
|
||||
#endif
|
||||
|
||||
text_len = strlen(pText);
|
||||
/* do all captured */
|
||||
pCurrent = pCapture;
|
||||
while(pCurrent)
|
||||
@@ -280,6 +292,8 @@
|
||||
if( (pCurrent->iOut == eOut) || (pCurrent->iAllFlag == 1) )
|
||||
{
|
||||
NETWrite(pCurrent->pCon->pSock,pText,strlen(pText));
|
||||
if (pText[text_len - 1] != '\n')
|
||||
NETWrite(pCurrent->pCon->pSock, "\n", 1);
|
||||
}
|
||||
pCurrent = pCurrent->pNext;
|
||||
}
|
||||
@@ -313,10 +327,15 @@
|
||||
|
||||
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);
|
||||
iLineCount++;
|
||||
|
||||
#if 0 /* Already done above */
|
||||
/* do all captured as well */
|
||||
pCurrent = pCapture;
|
||||
while(pCurrent)
|
||||
@@ -324,8 +343,11 @@
|
||||
if( (pCurrent->iOut == eOut) || (pCurrent->iAllFlag == 1) )
|
||||
{
|
||||
NETWrite(pCurrent->pCon->pSock,pText,strlen(pText));
|
||||
if (pText[text_len - 1] != '\n')
|
||||
NETWrite(pCurrent->pCon->pSock, "\n", 1);
|
||||
}
|
||||
pCurrent = pCurrent->pNext;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user