]> git.ipfire.org Git - thirdparty/sarg.git/commitdiff
Verbose output with correct period covered by the logs
authorFrederic Marchal <fmarchal@users.sourceforge.net>
Mon, 29 Sep 2014 19:49:26 +0000 (21:49 +0200)
committerFrederic Marchal <fmarchal@users.sourceforge.net>
Mon, 29 Sep 2014 19:49:26 +0000 (21:49 +0200)
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.

include/defs.h
log.c
readlog.c

index b60ade4daf276627756b010db90f1d3739edd305..60e5adbb49a83c7eee24ce7e92e174671617eb25 100755 (executable)
@@ -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 d19426ae1c8aee9b532f8e9b2f9f1bbe5e2933d6..4b36bd48bb3ad73c255912666db61a551a3fc522 100644 (file)
--- 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);
index c070338175288ed3d5339109ebaf96436379254d..6b009b0661dcfc9133f315713c90a5345ab5bb45 100644 (file)
--- 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 || idata<EarliestDate) {
+                       EarliestDate=idata;
+                       memcpy(&EarliestDateTime,&log_entry.EntryTime,sizeof(struct tm));
+               }
+               if (LatestDate<0 || idata>LatestDate) {
+                       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));
+       }
+}