Improved the interface of the LogTS function
This commit is contained in:
31
logv2.c
31
logv2.c
@ -9,7 +9,6 @@
|
|||||||
*/
|
*/
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <sys/time.h>
|
|
||||||
#include <logv2.h>
|
#include <logv2.h>
|
||||||
#include <sics.h>
|
#include <sics.h>
|
||||||
#include <splitter.h>
|
#include <splitter.h>
|
||||||
@ -41,15 +40,20 @@ typedef struct {
|
|||||||
|
|
||||||
static int callbackList;
|
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;
|
struct tm *time;
|
||||||
int year, month, day, hour, min, sec, usec;
|
int year, month, day, hour, min, sec, usec;
|
||||||
char delim = '-';
|
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);
|
time = localtime(&tv.tv_sec);
|
||||||
year = 1900 + time->tm_year;
|
year = 1900 + time->tm_year;
|
||||||
month = time->tm_mon + 1;
|
month = time->tm_mon + 1;
|
||||||
@ -73,7 +77,7 @@ static char *makeLogFileName(void)
|
|||||||
char *filename = NULL;
|
char *filename = NULL;
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
|
|
||||||
formatTimeStamp(timeStamp,sizeof(timeStamp),1);
|
formatTimeStamp(NULL,timeStamp,sizeof(timeStamp),1);
|
||||||
length = strlen(logTemplate) + strlen(timeStamp) + 30;
|
length = strlen(logTemplate) + strlen(timeStamp) + 30;
|
||||||
filename = malloc(length*sizeof(char));
|
filename = malloc(length*sizeof(char));
|
||||||
if(filename != NULL){
|
if(filename != NULL){
|
||||||
@ -109,8 +113,8 @@ static void checkLogFile(void)
|
|||||||
if(logFile != NULL && lineCount >= MAXFILELINES){
|
if(logFile != NULL && lineCount >= MAXFILELINES){
|
||||||
oldLogFile = strdup(logFilename);
|
oldLogFile = strdup(logFilename);
|
||||||
filename = makeLogFileName();
|
filename = makeLogFileName();
|
||||||
formatTimeStamp(timeStamp,sizeof(timeStamp),0);
|
formatTimeStamp(NULL,timeStamp,sizeof(timeStamp),0);
|
||||||
fprintf(logFile,"%s:sys:%d:Next logfile %s\n",timeStamp,INFO,filename);
|
fprintf(logFile,"%s:sys:INFO:Next logfile %s\n",timeStamp,filename);
|
||||||
LogClose(NULL);
|
LogClose(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,7 +129,7 @@ static void checkLogFile(void)
|
|||||||
logFile = fopen(filename,"w");
|
logFile = fopen(filename,"w");
|
||||||
strncpy(logFilename,filename,sizeof(logFilename));
|
strncpy(logFilename,filename,sizeof(logFilename));
|
||||||
if(oldLogFile != NULL){
|
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(oldLogFile);
|
||||||
}
|
}
|
||||||
free(filename);
|
free(filename);
|
||||||
@ -382,7 +386,7 @@ void LogIS(unsigned int severity, unsigned int subsystem,const char *format,...)
|
|||||||
|
|
||||||
|
|
||||||
formatSubsystem(subsystem,subText,sizeof(subText));
|
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
|
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 logData[2024], *logMessage = NULL;
|
||||||
char *dynMessage = NULL;
|
char *dynMessage = NULL;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
@ -423,6 +427,7 @@ void LogTS(const char *timeStamp, unsigned int severity, unsigned int subsystem,
|
|||||||
|
|
||||||
|
|
||||||
formatSubsystem(subsystem,subText,sizeof(subText));
|
formatSubsystem(subsystem,subText,sizeof(subText));
|
||||||
|
formatTimeStamp(tv, timeStamp,sizeof(timeStamp),0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
If we have enough space put the logData into our generous buffer. Else
|
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;
|
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
|
If we have enough space put the logData into our generous buffer. Else
|
||||||
|
3
logv2.h
3
logv2.h
@ -11,6 +11,7 @@
|
|||||||
#ifndef __LOGV2
|
#ifndef __LOGV2
|
||||||
#define __LOGV2
|
#define __LOGV2
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
severity codes
|
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 format The format string for the message
|
||||||
* \param ... The data to format
|
* \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,...);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user