diff --git a/src/log_format.cc b/src/log_format.cc index 9580b467..f3ec5fd5 100644 --- a/src/log_format.cc +++ b/src/log_format.cc @@ -308,9 +308,9 @@ void log_format::check_for_new_year(std::vector &dst, exttm etm, } if (diff > (60 * 24 * 60 * 60)) { off_year = 1; - } else if (diff > (15 * 24 * 60 * 60)) { + } else if (diff >= (24 * 60 * 60)) { off_month = 1; - } else if (diff > (12 * 60 * 60)) { + } else if (!(etm.et_flags & ETF_DAY_SET) && (diff >= (60 * 60))) { off_day = 1; } else if (!(etm.et_flags & ETF_DAY_SET)) { off_hour = 1; @@ -321,7 +321,8 @@ void log_format::check_for_new_year(std::vector &dst, exttm etm, if (!do_change) { return; } - log_debug("%d:detected year change", dst.size()); + log_debug("%d:detected time rollover; offsets=%d %d %d %d", dst.size(), + off_year, off_month, off_day, off_hour); for (iter = dst.begin(); iter != dst.end(); iter++) { time_t ot = iter->get_time(); struct tm otm; @@ -329,7 +330,7 @@ void log_format::check_for_new_year(std::vector &dst, exttm etm, gmtime_r(&ot, &otm); otm.tm_year -= off_year; otm.tm_mon -= off_month; - otm.tm_yday -= off_day; + otm.tm_mday -= off_day; otm.tm_hour -= off_hour; iter->set_time(tm2sec(&otm)); } @@ -731,8 +732,8 @@ log_format::scan_result_t external_log_format::scan(std::vector &dst, } if (!((log_time_tm.et_flags & ETF_DAY_SET) && - (log_time_tm.et_flags & ETF_MONTH_SET) && - (log_time_tm.et_flags & ETF_YEAR_SET))) { + (log_time_tm.et_flags & ETF_MONTH_SET) && + (log_time_tm.et_flags & ETF_YEAR_SET))) { this->check_for_new_year(dst, log_time_tm, log_tv); } diff --git a/test/Makefile.am b/test/Makefile.am index 5d58b0e6..b15d7d87 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -279,6 +279,7 @@ dist_noinst_DATA = \ logfile_openam.0 \ logfile_plain.0 \ logfile_pretty.0 \ + logfile_rollover.0 \ logfile_strace_log.0 \ logfile_syslog.0 \ logfile_syslog.1 \ diff --git a/test/logfile_rollover.0 b/test/logfile_rollover.0 new file mode 100644 index 00000000..f37fbabd --- /dev/null +++ b/test/logfile_rollover.0 @@ -0,0 +1,6 @@ +00:00:00.000 foo DEBUG some super duper message +01:00:00.000 foo DEBUG some super duper message +02:00:00.000 foo DEBUG some super duper message +03:00:00.000 foo DEBUG some super duper message +00:00:00.000 bar DEBUG some super duper message next day (only one hour) +00:01:00.000 bar DEBUG some super duper message next day (only one hour) diff --git a/test/test_logfile.sh b/test/test_logfile.sh index 01b935d2..89512ba8 100644 --- a/test/test_logfile.sh +++ b/test/test_logfile.sh @@ -62,6 +62,18 @@ Dec 03 09:23:38 2006 -- 000 Jan 03 09:47:02 2007 -- 000 EOF +touch -t 200711030000 ${srcdir}/logfile_rollover.0 +run_test ./drive_logfile -t -f generic_log ${srcdir}/logfile_rollover.0 + +check_output "Generic timestamp interpreted incorrectly for day rollover?" < logfile_syslog.1.gz run_test ./drive_logfile -t -f syslog_log logfile_syslog.1.gz