Include outcode and continuation marker, move testlog test command up.

Moving the testlog command up reduces the dependency loops in servlog
This commit is contained in:
Douglas Clowes
2014-04-03 11:59:26 +11:00
parent bab07abab8
commit 79be4c9422
2 changed files with 53 additions and 27 deletions

View File

@@ -82,6 +82,28 @@ typedef struct __LogLog {
static pCaptureEntry pCapture = NULL; static pCaptureEntry pCapture = NULL;
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
static char* OutCodeToTxt(OutCode eOut)
{
switch (eOut) {
case eInternal: return "Int"; /* internal */
case eCommand: return "Cmd"; /* reserved, not used */
case eHWError: return "ErH"; /* reserved, used only for SICSLog */
case eInError: return "ErI"; /* reserved, used as a mark in the handling of output codes */
case eStatus: return "Sta"; /* reserved, deprecated */
case eValue: return "Val"; /* value reponse: copied into Tcl */
case eStart: return "Beg"; /* start message */
case eFinish: return "End"; /* finish message */
case eEvent: return "Evt"; /* some callback messages */
case eWarning: return "Wrn"; /* warnings */
case eError: return "Err"; /* error: copied into Tcl */
case eHdbValue: return "HVa"; /* hipadaba value chnage */
case eHdbEvent: return "HEv"; /* Hipadaba event */
case eLog: return "Log"; /* log message: is always written to client */
case eLogError: return "ErL"; /* error message to log: is always written to client */
}
return "???";
}
int KillCapture(SConnection * pCon) int KillCapture(SConnection * pCon)
{ {
pCaptureEntry pCurrent, pTemp; pCaptureEntry pCurrent, pTemp;
@@ -325,7 +347,7 @@ static void SICSLogWriteFile(char *pText, OutCode eOut, struct timeval *tp)
if (iLineCount == 0) if (iLineCount == 0)
fprintf(fLogFile, "%s: <<<open logfile>>>\n", timestamp(NULL)); fprintf(fLogFile, "%s: <<<open logfile>>>\n", timestamp(NULL));
fprintf(fLogFile, "%s: ", timestamp(tp)); fprintf(fLogFile, "%s:%s:", timestamp(tp), OutCodeToTxt(eOut));
fprintf(fLogFile, "%s", pText); fprintf(fLogFile, "%s", pText);
if (text_len < 1 || pText[text_len - 1] != '\n') if (text_len < 1 || pText[text_len - 1] != '\n')
fprintf(fLogFile, "\n"); fprintf(fLogFile, "\n");
@@ -351,6 +373,8 @@ void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp)
buf[idx++] = '\0'; buf[idx++] = '\0';
SICSLogWriteFile(buf, eOut, tp); SICSLogWriteFile(buf, eOut, tp);
idx = 0; idx = 0;
buf[idx++] = '*';
buf[idx++] = ':';
} else if (*cp == '\r') { } else if (*cp == '\r') {
buf[idx++] = '\\'; buf[idx++] = '\\';
buf[idx++] = 'r'; buf[idx++] = 'r';
@@ -372,6 +396,8 @@ void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp)
buf[idx++] = '\0'; buf[idx++] = '\0';
SICSLogWriteFile(buf, eOut, tp); SICSLogWriteFile(buf, eOut, tp);
idx = 0; idx = 0;
buf[idx++] = '*';
buf[idx++] = ':';
} }
} }
if (idx > 0) { if (idx > 0) {
@@ -521,29 +547,3 @@ void SICSLogPrintf(OutCode eOut, const char *fmt, ...)
SICSLogWrite(buf, eOut); SICSLogWrite(buf, eOut);
return; return;
} }
/* Test of the logging facilities */
int testLogCmd(SConnection *pCon, SicsInterp *pInter, void *pData,
int argc, char *argv[]) {
char lbuf[2048];
char sbuf[1000];
int i;
SICSLogWrite("Multiline:\nLine 1\r\nLine 2\r\nLine 3\r\n", eStatus);
memset(lbuf, 0, sizeof(lbuf));
memset(sbuf, ' ', sizeof(sbuf));
SICSLogPrintf(eStatus, "Hexlog %d all zero bytes", sizeof(lbuf));
SICSLogWriteHex(lbuf, sizeof(lbuf), eStatus);
for (i = 0; i <= 128; ++i)
sbuf[i] = sbuf[sizeof(sbuf) - 1 - i] = i;
sbuf[sizeof(sbuf) / 2] = '!';
SICSLogPrintf(eStatus, "Hexlog %d mid space bytes", sizeof(sbuf));
SICSLogWriteHex(sbuf, sizeof(sbuf), eStatus);
for (i = 0; i < 1000; ++i)
sbuf[i] = ' ' + (i % 96);
sbuf[sizeof(sbuf) - 1] = '\0';
SICSLogWrite("Very long line 1000 bytes", eStatus);
SICSLogWrite(sbuf, eStatus);
SCSendOK(pCon);
return OKOK;
}

View File

@@ -290,6 +290,32 @@ static int MacroFileEvalGlob(SConnection * pCon, SicsInterp * pInter, void *pDat
SCSendOK(pCon); SCSendOK(pCon);
return rv; return rv;
} }
/* Test of the logging facilities */
int testLogCmd(SConnection *pCon, SicsInterp *pInter, void *pData,
int argc, char *argv[]) {
char lbuf[2048];
char sbuf[1000];
int i;
SICSLogWrite("Multiline:\nLine 1\r\nLine 2\r\nLine 3\r\n", eStatus);
memset(lbuf, 0, sizeof(lbuf));
memset(sbuf, ' ', sizeof(sbuf));
SICSLogPrintf(eStatus, "Hexlog %d all zero bytes", sizeof(lbuf));
SICSLogWriteHex(lbuf, sizeof(lbuf), eStatus);
for (i = 0; i <= 128; ++i)
sbuf[i] = sbuf[sizeof(sbuf) - 1 - i] = i;
sbuf[sizeof(sbuf) / 2] = '!';
SICSLogPrintf(eStatus, "Hexlog %d mid space bytes", sizeof(sbuf));
SICSLogWriteHex(sbuf, sizeof(sbuf), eStatus);
for (i = 0; i < 1000; ++i)
sbuf[i] = ' ' + (i % 96);
sbuf[sizeof(sbuf) - 1] = '\0';
SICSLogWrite("Very long line 1000 bytes", eStatus);
SICSLogWrite(sbuf, eStatus);
SCSendOK(pCon);
return OKOK;
}
void SiteInit(void) { void SiteInit(void) {
int NetWatchInit(void); int NetWatchInit(void);
NetWatchInit(); NetWatchInit();