This is the first working version of the new logging system. Some work

in fine tuning still needs to be done. But is reasonably OK now.
This commit is contained in:
2016-02-11 13:40:31 +01:00
parent b1cda3f579
commit 66466c1c0f
56 changed files with 420 additions and 1845 deletions

37
logv2.c
View File

@ -24,9 +24,11 @@ static unsigned int MAXFILELINES = 100000;
static unsigned int lineCount = 0;
static char logTemplate[1024];
static char logFilename[1024];
static unsigned int logDisabled = 0;
static int unsigned logConfigured = 0;
/*================ The default log level =======================================*/
static unsigned int globalLogLevel = 7;
static unsigned int globalLogLevel = 4;
/*========= The list of sub systems for which full logging is enabled ==========*/
static int subList;
/*================== Callback management =======================================*/
@ -79,7 +81,7 @@ static char *makeLogFileName(void)
return filename;
}
/*----------------------------------------------------------------------------*/
static void LogClose(void *data)
void LogClose(void *data)
{
if(logFile != NULL){
fclose(logFile);
@ -93,6 +95,10 @@ static void checkLogFile(void)
{
char *filename = NULL;
if(logDisabled || logConfigured == 0){
return;
}
/*
close when full
*/
@ -116,11 +122,21 @@ static void checkLogFile(void)
static void writeLog(char *logMessage)
{
int nChar;
unsigned int end;
char *pPtr;
const char delim = '\n';
if(logMessage == NULL){
return;
}
/*
remove a trailing newline
*/
end = strlen(logMessage);
if(logMessage[end-1] == delim){
logMessage[end-1] = '\0';
}
if(logFile != NULL){
nChar = fprintf(logFile,"%s\n",logMessage);
@ -134,6 +150,11 @@ static unsigned int logFilter(unsigned int severity, const char *subsystem)
int status;
char buffer[1024];
if(logDisabled || logConfigured == 0){
return 1;
}
/*
If it is in the list of enabled subsystems, everything is logged
*/
@ -146,12 +167,14 @@ static unsigned int logFilter(unsigned int severity, const char *subsystem)
status = LLDnodePtr2Next(subList);
}
/*
test against the global log level
*/
if(severity >= globalLogLevel){
if(severity > globalLogLevel){
return 1;
}
return 0;
}
/*=============================================================================*/
@ -246,7 +269,7 @@ void Log(unsigned int severity, const char *subsystem,const char *format,...)
{
char severityTXT[60];
char timeStamp[132];
char logData[2024], logLine[3072];
char logData[2024], logLine[3072], *pPtr = NULL;
char *dynMessage = NULL, *logMessage, *fullMessage = NULL;
va_list ap;
int dataLength;
@ -415,6 +438,7 @@ static int LogConfigAction(SConnection * pCon, SicsInterp * pSics,
} else if(strcmp(argv[1],"logtemplate") == 0){
if(argc > 2){
strncpy(logTemplate,argv[2],sizeof(logTemplate));
logConfigured = 1;
SCSendOK(pCon);
} else {
SCPrintf(pCon,eValue,"logconfig.logtemplate = %s", logTemplate);
@ -474,6 +498,11 @@ static int LogConfigAction(SConnection * pCon, SicsInterp * pSics,
return 1;
}
/*-----------------------------------------------------------------------------*/
void DisableLog(void)
{
logDisabled = 1;
}
/*-----------------------------------------------------------------------------*/
void Logv2Init(void)
{
subList = LLDstringCreate();