- do not allow logger to write more than once per period
- fixed bug in statistics.c
This commit is contained in:
27
logger.c
27
logger.c
@ -20,8 +20,9 @@ struct Logger {
|
||||
char *old;
|
||||
int oldsize;
|
||||
int period;
|
||||
time_t last, lastWrite;
|
||||
time_t last, lastWrite, omitTime;
|
||||
int numeric;
|
||||
float omitValue;
|
||||
int exact;
|
||||
Logger *next;
|
||||
};
|
||||
@ -30,6 +31,7 @@ static char *dir = NULL;
|
||||
static Logger *list;
|
||||
static time_t lastLife = 0;
|
||||
static time_t lastWritten = 0;
|
||||
static time_t omitCheck = 0;
|
||||
/*--------------------------------------------------------------------------*/
|
||||
char *LoggerName(Logger * log)
|
||||
{
|
||||
@ -238,6 +240,8 @@ int LoggerWrite(Logger * log, time_t now, int period, char *value)
|
||||
time_t h0;
|
||||
static int yday = -1;
|
||||
struct tm *tm;
|
||||
char *valp;
|
||||
char buf[32];
|
||||
|
||||
int l;
|
||||
FILE *fil;
|
||||
@ -283,6 +287,25 @@ int LoggerWrite(Logger * log, time_t now, int period, char *value)
|
||||
if (fil)
|
||||
fclose(fil);
|
||||
}
|
||||
if (now < log->last + log->period && strcmp(log->old, value) != 0) {
|
||||
log->omitValue = strtod(value, &valp);
|
||||
if (value != valp) {
|
||||
log->omitTime = now;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
log->omitTime = 0;
|
||||
}
|
||||
if (now > omitCheck + 5) { /* check for omitted values only every 5 seconds */
|
||||
for (p = list; p != NULL; p = p->next) {
|
||||
if (p->omitTime > 0 && now > p->omitTime + p->period) {
|
||||
snprintf(buf, sizeof buf, "%g", p->omitValue);
|
||||
LoggerWrite0(p, p->omitTime, p->period, buf);
|
||||
p->omitTime = 0;
|
||||
}
|
||||
}
|
||||
omitCheck = now;
|
||||
}
|
||||
return LoggerWrite0(log, now, period, value);
|
||||
}
|
||||
|
||||
@ -398,6 +421,8 @@ Logger *LoggerMake(char *name, int period, int exact)
|
||||
t = lastLife + period;
|
||||
}
|
||||
LoggerWrite(log, t, period, ""); /* value was undefined since last life of server */
|
||||
} else {
|
||||
LoggerSetPeriod(log, period);
|
||||
}
|
||||
return log;
|
||||
}
|
||||
|
Reference in New Issue
Block a user