From: Frederic Marchal Date: Mon, 29 Sep 2014 19:49:26 +0000 (+0200) Subject: Verbose output with correct period covered by the logs X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a943fc185120fb4b7e22bdadfa3e8f87b9d8dc8;p=thirdparty%2Fsarg.git Verbose output with correct period covered by the logs Previous versions reported the period covered by the log but it was, in fact, the period extracted from the log limited to the requested range. Now, two distinct messages are displayed in verbose mode. The first is the period really covered by the log files. The second is the range taken into account to produce the report. --- diff --git a/include/defs.h b/include/defs.h index b60ade4..60e5adb 100755 --- a/include/defs.h +++ b/include/defs.h @@ -252,6 +252,7 @@ void make_index(void); // readlog.c int ReadLogFile(struct ReadLogDataStruct *Filter); +void GetLogPeriod(struct tm *Start,struct tm *End); // realtime.c void realtime(void); diff --git a/log.c b/log.c index d19426a..4b36bd4 100644 --- a/log.c +++ b/log.c @@ -713,12 +713,19 @@ int main(int argc,char *argv[]) exit(EXIT_SUCCESS); } - if (ReadFilter.DateRange[0]!='\0') { + if (debug) { char date0[30], date1[30]; + struct tm Start,End; - strftime(date0,sizeof(date0),"%d/%m/%Y",&period.start); - strftime(date1,sizeof(date1),"%d/%m/%Y",&period.end); + GetLogPeriod(&Start,&End); + strftime(date0,sizeof(date0),"%x",&Start); + strftime(date1,sizeof(date1),"%x",&End); + // TRANSLATORS: The %s are the start and end dates in locale format. debuga(_("Period covered by log files: %s-%s\n"),date0,date1); + strftime(date0,sizeof(date0),"%x",&period.start); + strftime(date1,sizeof(date1),"%x",&period.end); + // TRANSLATORS: The %s are the start and end dates in locale format. + debuga(_("Period extracted from log files: %s-%s\n"),date0,date1); getperiod_fromrange(&period,dfrom,duntil); } if (getperiod_buildtext(&period)<0) { @@ -726,9 +733,6 @@ int main(int argc,char *argv[]) exit(EXIT_FAILURE); } - if(debug) - debuga(_("Period: %s\n"),period.text); - process_start_time=time(NULL); if(DataFile[0] != '\0') data_file(tmp); diff --git a/readlog.c b/readlog.c index c070338..6b009b0 100644 --- a/readlog.c +++ b/readlog.c @@ -126,6 +126,14 @@ static int mindate=0; static int maxdate=0; //! Count the number of excluded records. static unsigned long int excluded_count[ER_Last]; +//! Earliest date found in the log. +static int EarliestDate=-1; +//! The earliest date in time format. +static struct tm EarliestDateTime; +//! Latest date found in the log. +static int LatestDate=-1; +//! The latest date in time format. +static struct tm LatestDateTime; /*! Read a single log file. @@ -378,6 +386,14 @@ static void ReadOneLogFile(struct ReadLogDataStruct *Filter,const char *arq) if(debugm) printf("DATE=%s IDATA=%d DFROM=%d DUNTIL=%d\n",Filter->DateRange,idata,dfrom,duntil); + if (EarliestDate<0 || idataLatestDate) { + LatestDate=idata; + memcpy(&LatestDateTime,&log_entry.EntryTime,sizeof(struct tm)); + } if(Filter->DateRange[0] != '\0'){ if(idata < dfrom || idata > duntil) { excluded_count[ER_OutOfDateRange]++; @@ -813,8 +829,22 @@ int ReadLogFile(struct ReadLogDataStruct *Filter) debuga(_("Log with invalid format\n")); } - if (debugz) - debugaz(_("period=%s\n"),period.text); - return((totregsg!=0) ? 1 : 0); } + +/*! + * Get the start and end date of the period covered by the log files. + */ +void GetLogPeriod(struct tm *Start,struct tm *End) +{ + if (EarliestDate>=0) { + memcpy(Start,&EarliestDateTime,sizeof(struct tm)); + } else { + memset(Start,0,sizeof(struct tm)); + } + if (LatestDate>=0) { + memcpy(End,&LatestDateTime,sizeof(struct tm)); + } else { + memset(End,0,sizeof(struct tm)); + } +}