diff --git a/logv2.c b/logv2.c index ed62131b..6023f760 100644 --- a/logv2.c +++ b/logv2.c @@ -9,7 +9,6 @@ */ #include #include -#include #include #include #include @@ -41,15 +40,20 @@ typedef struct { static int callbackList; /*----------------------------------------------------------------------------*/ -static void formatTimeStamp(char *buffer, unsigned int bufferLength, unsigned int small) +static void formatTimeStamp(struct timeval *tp, + char *buffer, unsigned int bufferLength, unsigned int small) { - struct timeval tv; struct tm *time; int year, month, day, hour, min, sec, usec; char delim = '-'; + struct timeval tv; + + if(tp == NULL){ + gettimeofday(&tv, NULL); + } else { + tv = *tp; + } - gettimeofday(&tv, NULL); - time = localtime(&tv.tv_sec); time = localtime(&tv.tv_sec); year = 1900 + time->tm_year; month = time->tm_mon + 1; @@ -73,7 +77,7 @@ static char *makeLogFileName(void) char *filename = NULL; unsigned int length; - formatTimeStamp(timeStamp,sizeof(timeStamp),1); + formatTimeStamp(NULL,timeStamp,sizeof(timeStamp),1); length = strlen(logTemplate) + strlen(timeStamp) + 30; filename = malloc(length*sizeof(char)); if(filename != NULL){ @@ -109,8 +113,8 @@ static void checkLogFile(void) if(logFile != NULL && lineCount >= MAXFILELINES){ oldLogFile = strdup(logFilename); filename = makeLogFileName(); - formatTimeStamp(timeStamp,sizeof(timeStamp),0); - fprintf(logFile,"%s:sys:%d:Next logfile %s\n",timeStamp,INFO,filename); + formatTimeStamp(NULL,timeStamp,sizeof(timeStamp),0); + fprintf(logFile,"%s:sys:INFO:Next logfile %s\n",timeStamp,filename); LogClose(NULL); } @@ -125,7 +129,7 @@ static void checkLogFile(void) logFile = fopen(filename,"w"); strncpy(logFilename,filename,sizeof(logFilename)); if(oldLogFile != NULL){ - fprintf(logFile,"%s:sys:%d:Previous logfile %s\n",timeStamp,INFO,oldLogFile); + fprintf(logFile,"%s:sys:INFO:Previous logfile %s\n",timeStamp,oldLogFile); free(oldLogFile); } free(filename); @@ -382,7 +386,7 @@ void LogIS(unsigned int severity, unsigned int subsystem,const char *format,...) formatSubsystem(subsystem,subText,sizeof(subText)); - formatTimeStamp(timeStamp,sizeof(timeStamp),0); + formatTimeStamp(NULL, timeStamp,sizeof(timeStamp),0); /* If we have enough space put the logData into our generous buffer. Else @@ -413,9 +417,9 @@ void LogIS(unsigned int severity, unsigned int subsystem,const char *format,...) } /*-------------------------------------------------------------------------------*/ -void LogTS(const char *timeStamp, unsigned int severity, unsigned int subsystem,const char *format,...) +void LogTS(struct timeval *tv, unsigned int severity, unsigned int subsystem,const char *format,...) { - char subText[30]; + char subText[30], timeStamp[256]; char logData[2024], *logMessage = NULL; char *dynMessage = NULL; va_list ap; @@ -423,6 +427,7 @@ void LogTS(const char *timeStamp, unsigned int severity, unsigned int subsystem, formatSubsystem(subsystem,subText,sizeof(subText)); + formatTimeStamp(tv, timeStamp,sizeof(timeStamp),0); /* If we have enough space put the logData into our generous buffer. Else @@ -462,7 +467,7 @@ void Log(unsigned int severity, const char *subsystem,const char *format,...) int dataLength; - formatTimeStamp(timeStamp,sizeof(timeStamp),0); + formatTimeStamp(NULL,timeStamp,sizeof(timeStamp),0); /* If we have enough space put the logData into our generous buffer. Else diff --git a/logv2.h b/logv2.h index fb60c6dd..dc523bba 100644 --- a/logv2.h +++ b/logv2.h @@ -11,6 +11,7 @@ #ifndef __LOGV2 #define __LOGV2 #include +#include /* severity codes @@ -62,7 +63,7 @@ void LogIS(unsigned int severity, unsigned int subsystem,const char *format,...) * \param format The format string for the message * \param ... The data to format */ -void LogTS(const char *timeStamp, unsigned int severity, unsigned int subsystem,const char *format,...); +void LogTS(struct timeval *tv, unsigned int severity, unsigned int subsystem,const char *format,...);