Changes to logging
Add 'L' to 'M', 'N', 'D' log flags (for consistency) Replace colon (':') in logfilenames with minus ('-') Suppress spurious blank lines in logfile from line terminators Add filename to open/close messages for chaining convenience
This commit is contained in:
19
conman.c
19
conman.c
@ -789,17 +789,17 @@ static int isOK(const char *buffer)
|
|||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
static void testAndWriteSICSLog(SConnection * self, char *buffer, int iOut)
|
static void testAndWriteSICSLog(SConnection * self, char *buffer, int iOut)
|
||||||
{
|
{
|
||||||
char *tp;
|
char tp;
|
||||||
/* We don't want to log the "OK" messages */
|
/* We don't want to log the "OK" messages */
|
||||||
if (isOK(buffer))
|
if (isOK(buffer))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (SCinMacro(self)) {
|
if (SCinMacro(self)) {
|
||||||
tp = "M";
|
tp = 'M';
|
||||||
if (sicsdebug())
|
if (sicsdebug())
|
||||||
tp = "D";
|
tp = 'D';
|
||||||
} else
|
} else
|
||||||
tp = "N";
|
tp = 'N';
|
||||||
switch (iOut) {
|
switch (iOut) {
|
||||||
case eStatus:
|
case eStatus:
|
||||||
case eStart:
|
case eStart:
|
||||||
@ -812,22 +812,25 @@ static void testAndWriteSICSLog(SConnection * self, char *buffer, int iOut)
|
|||||||
case eError:
|
case eError:
|
||||||
case eWarning:
|
case eWarning:
|
||||||
/* Log it */
|
/* Log it */
|
||||||
SICSLogPrintf(iOut, "%s:%s", tp, buffer);
|
SICSLogWriteCode(buffer, iOut, tp);
|
||||||
return;
|
return;
|
||||||
case eValue:
|
case eValue:
|
||||||
if (sicsdebug() || !SCinMacro(self)) {
|
if (sicsdebug() || !SCinMacro(self)) {
|
||||||
/* Log it */
|
/* Log it */
|
||||||
SICSLogPrintf(iOut, "%s:%s", tp, buffer);
|
SICSLogWriteCode(buffer, iOut, tp);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
/* Suppressed */
|
/* Suppressed */
|
||||||
/* SICSLogPrintf(iOut, "%s!:%s", tp, buffer); */
|
#if 0
|
||||||
|
tp = tolower(tp);
|
||||||
|
SICSLogWriteCode(buffer, iOut, tp);
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printf("Unrecognized ouput code %d in testAndWriteSICSLog: FIXME!!!\n", iOut);
|
printf("Unrecognized ouput code %d in testAndWriteSICSLog: FIXME!!!\n", iOut);
|
||||||
SICSLogPrintf(iOut, "%s:%s", tp, buffer);
|
SICSLogWriteCode(buffer, iOut, tp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
73
servlog.c
73
servlog.c
@ -239,7 +239,7 @@ static int HasLineFeed(char *pText)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static const char* timestamp(struct timeval *tp) {
|
static const char* timestamp(struct timeval *tp, char delim) {
|
||||||
static char ts[80];
|
static char ts[80];
|
||||||
int year, month, day;
|
int year, month, day;
|
||||||
int hour, min, sec, usec;
|
int hour, min, sec, usec;
|
||||||
@ -257,8 +257,8 @@ static const char* timestamp(struct timeval *tp) {
|
|||||||
min = time->tm_min;
|
min = time->tm_min;
|
||||||
sec = time->tm_sec;
|
sec = time->tm_sec;
|
||||||
usec = (int) tv.tv_usec;
|
usec = (int) tv.tv_usec;
|
||||||
snprintf(ts, 80, "%04d-%02d-%02dT%02d:%02d:%02d.%06d",
|
snprintf(ts, 80, "%04d-%02d-%02dT%02d%c%02d%c%02d.%06d",
|
||||||
year, month, day, hour, min, sec, usec);
|
year, month, day, hour, delim, min, delim, sec, usec);
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,12 +270,13 @@ static FILE *fLogFile = NULL;
|
|||||||
static int iFile = 0;
|
static int iFile = 0;
|
||||||
static int iLineCount = 0;
|
static int iLineCount = 0;
|
||||||
static int iLogUsable = 1;
|
static int iLogUsable = 1;
|
||||||
|
static char filnam[512];
|
||||||
|
static char prevfilnam[512];
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int OpenVerifyLogFile()
|
int OpenVerifyLogFile()
|
||||||
{
|
{
|
||||||
char pFile[256];
|
char pFile[256];
|
||||||
char filnam[512];
|
|
||||||
char *pChar = NULL;
|
char *pChar = NULL;
|
||||||
char fPath[1024];
|
char fPath[1024];
|
||||||
|
|
||||||
@ -289,7 +290,11 @@ int OpenVerifyLogFile()
|
|||||||
strlcpy(pFile, pChar, 255);
|
strlcpy(pFile, pChar, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(filnam, 511, "%s%s_%19.19s.%02d.log", fPath, pFile, timestamp(NULL), iFile);
|
snprintf(filnam, 511, "%s%s_%19.19s.%02d.log", fPath, pFile, timestamp(NULL, '-'), iFile);
|
||||||
|
iFile++;
|
||||||
|
if (iFile >= MAXFILES) {
|
||||||
|
iFile = 0;
|
||||||
|
}
|
||||||
|
|
||||||
fLogFile = fopen(filnam, "w");
|
fLogFile = fopen(filnam, "w");
|
||||||
if (!fLogFile) {
|
if (!fLogFile) {
|
||||||
@ -337,26 +342,32 @@ static void SICSLogWriteFile(char *pText, OutCode eOut, struct timeval *tp)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
iLogUsable = OpenVerifyLogFile();
|
iLogUsable = OpenVerifyLogFile();
|
||||||
|
iLineCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* switch file if too many lines */
|
/* switch file if too many lines */
|
||||||
if (iLineCount >= MAXLOG) {
|
if (iLineCount >= MAXLOG) {
|
||||||
fprintf(fLogFile, "%s: <<<close logfile>>>\n", timestamp(NULL));
|
strcpy(prevfilnam, filnam);
|
||||||
fclose(fLogFile);
|
FILE *prevlog = fLogFile;
|
||||||
fLogFile = NULL;
|
|
||||||
iFile++;
|
|
||||||
iLineCount = 0;
|
|
||||||
if (iFile >= MAXFILES) {
|
|
||||||
iFile = 0;
|
|
||||||
}
|
|
||||||
iLogUsable = OpenVerifyLogFile();
|
iLogUsable = OpenVerifyLogFile();
|
||||||
|
iLineCount = 0;
|
||||||
|
fprintf(prevlog, "%s: <<<close logfile>>> to %s\n",
|
||||||
|
timestamp(NULL, ':'),
|
||||||
|
filnam);
|
||||||
|
fclose(prevlog);
|
||||||
|
if (1 == iLogUsable) {
|
||||||
|
fprintf(fLogFile, "%s: <<<open logfile>>> from %s\n",
|
||||||
|
timestamp(NULL, ':'),
|
||||||
|
prevfilnam);
|
||||||
|
iLineCount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (1 == iLogUsable) {
|
if (1 == iLogUsable) {
|
||||||
|
|
||||||
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:%s:", timestamp(tp), OutCodeToTxt(eOut));
|
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");
|
||||||
@ -365,10 +376,10 @@ static void SICSLogWriteFile(char *pText, OutCode eOut, struct timeval *tp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp)
|
void SICSLogWriteTimeCode(char *pText, OutCode eOut, struct timeval *tp, char code)
|
||||||
{
|
{
|
||||||
char buf[200];
|
char buf[200];
|
||||||
const char *cp = pText;
|
const char *cp;
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
|
||||||
@ -376,6 +387,11 @@ void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp)
|
|||||||
gettimeofday(&tv, NULL);
|
gettimeofday(&tv, NULL);
|
||||||
tp = &tv;
|
tp = &tv;
|
||||||
}
|
}
|
||||||
|
if (isalnum(code)) {
|
||||||
|
buf[idx++] = code;
|
||||||
|
buf[idx++] = ':';
|
||||||
|
}
|
||||||
|
cp = pText;
|
||||||
while (*cp) {
|
while (*cp) {
|
||||||
if (*cp == '\n') {
|
if (*cp == '\n') {
|
||||||
buf[idx++] = '\n';
|
buf[idx++] = '\n';
|
||||||
@ -409,6 +425,9 @@ void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp)
|
|||||||
buf[idx++] = ':';
|
buf[idx++] = ':';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/* Suppress the spurious blank lines caused by trailing newlines */
|
||||||
|
if (idx == 2 && buf[0] == '*' && buf[1] == ':')
|
||||||
|
return;
|
||||||
if (idx > 0) {
|
if (idx > 0) {
|
||||||
buf[idx++] = '\n';
|
buf[idx++] = '\n';
|
||||||
buf[idx++] = '\0';
|
buf[idx++] = '\0';
|
||||||
@ -416,11 +435,19 @@ void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SICSLogWriteCode(char *pText, OutCode eOut, char code)
|
||||||
|
{
|
||||||
|
SICSLogWriteTimeCode(pText, eOut, NULL, code);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SICSLogWriteTime(char *pText, OutCode eOut, struct timeval *tp)
|
||||||
|
{
|
||||||
|
SICSLogWriteTimeCode(pText, eOut, tp, 'L');
|
||||||
|
}
|
||||||
|
|
||||||
void SICSLogWrite(char *pText, OutCode eOut)
|
void SICSLogWrite(char *pText, OutCode eOut)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
SICSLogWriteTime(pText, eOut, NULL);
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
SICSLogWriteTime(pText, eOut, &tv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SICSLogWriteHexTime(const char *text, int count, OutCode eOut,
|
void SICSLogWriteHexTime(const char *text, int count, OutCode eOut,
|
||||||
@ -493,9 +520,7 @@ void SICSLogWriteHexTime(const char *text, int count, OutCode eOut,
|
|||||||
|
|
||||||
void SICSLogWriteHex(const char *text, int count, OutCode eOut)
|
void SICSLogWriteHex(const char *text, int count, OutCode eOut)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
SICSLogWriteHexTime(text, count, eOut, NULL);
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
SICSLogWriteHexTime(text, count, eOut, &tv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SICSLogTimePrintf(OutCode eOut, struct timeval *tp, const char *fmt,
|
void SICSLogTimePrintf(OutCode eOut, struct timeval *tp, const char *fmt,
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#include "Scommon.h"
|
#include "Scommon.h"
|
||||||
void SICSLogWrite(char *ptext, OutCode eOut);
|
void SICSLogWrite(char *ptext, OutCode eOut);
|
||||||
void SICSLogWriteTime(char *ptext, OutCode eOut, struct timeval *tp);
|
void SICSLogWriteTime(char *ptext, OutCode eOut, struct timeval *tp);
|
||||||
|
void SICSLogWriteCode(char *ptext, OutCode eOut, char code);
|
||||||
|
void SICSLogWriteTimeCode(char *ptext, OutCode eOut, struct timeval *tp, char code);
|
||||||
void SICSLogWriteHex(const char *text, int count, OutCode eOut);
|
void SICSLogWriteHex(const char *text, int count, OutCode eOut);
|
||||||
void SICSLogWriteHexTime(const char *text, int count, OutCode eOut,
|
void SICSLogWriteHexTime(const char *text, int count, OutCode eOut,
|
||||||
struct timeval *tp);
|
struct timeval *tp);
|
||||||
|
Reference in New Issue
Block a user