From 17e27776ea152509e1095bbf80f5af65bc7a7997 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 4 May 2020 12:24:24 +0200 Subject: Add a -log-before & -log-after predicate With the file name heuristic for -before and -after in place, we might want a way for the user to disable it. For now, we simply do this by providing a new set of predicates without the filter. In the future, we might have a --disable-heuristics switch to disable the heuristics, in case we ever add more. --- src/filters/log.rs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'src/filters') diff --git a/src/filters/log.rs b/src/filters/log.rs index 1728d4b..2f4a6a0 100644 --- a/src/filters/log.rs +++ b/src/filters/log.rs @@ -92,10 +92,14 @@ pub fn weekday(weekdays: HashSet) -> Box { } #[derive(Debug, Clone)] -struct TimeFilter(Option>, Option>); +struct TimeFilter(Option>, Option>, bool); impl Filter for TimeFilter { fn filter_early(&self, early_log: &EarlyLogResult) -> Inclusion { + // Ignore the filename heuristic if the user wishes so. + if !self.2 { + return Inclusion::Unknown + } early_log .log_file .file_name() @@ -147,7 +151,7 @@ fn datetime_from_filename(name: &OsStr) -> Option> { /// If a bound is not given, -Infinity is assumed for the lower bound, and Infinity for the upper /// bound. pub fn time(lower: Option>, upper: Option>) -> Box { - Box::new(TimeFilter(lower, upper)) + Box::new(TimeFilter(lower, upper, true)) } /// A `LogFilter` that only accepts logs after the given date. @@ -164,6 +168,24 @@ pub fn before(when: DateTime) -> Box { time(None, Some(when)) } +/// A `LogFilter` that only accepts logs in the given time frame. +/// +/// Compared to [`time`][time], this filter ignores the file name. This can result in more accurate +/// results if you renamed logs, but if also leads to a worse runtime. +pub fn log_time(lower: Option>, upper: Option>) -> Box { + Box::new(TimeFilter(lower, upper, false)) +} + +/// Like [`after`][after], but ignores the file name for date calculations. +pub fn log_after(when: DateTime) -> Box { + log_time(Some(when), None) +} + +/// Like [`before`][before], but ignores the file name for date calculations. +pub fn log_before(when: DateTime) -> Box { + log_time(None, Some(when)) +} + #[cfg(test)] mod tests { use super::*; -- cgit v1.2.3