aboutsummaryrefslogtreecommitdiff
path: root/src/filters
diff options
context:
space:
mode:
Diffstat (limited to 'src/filters')
-rw-r--r--src/filters/log.rs26
1 files changed, 24 insertions, 2 deletions
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<Weekday>) -> Box<dyn LogFilter> {
}
#[derive(Debug, Clone)]
-struct TimeFilter(Option<DateTime<Utc>>, Option<DateTime<Utc>>);
+struct TimeFilter(Option<DateTime<Utc>>, Option<DateTime<Utc>>, bool);
impl Filter<EarlyLogResult, LogResult> 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<DateTime<Utc>> {
/// If a bound is not given, -Infinity is assumed for the lower bound, and Infinity for the upper
/// bound.
pub fn time(lower: Option<DateTime<Utc>>, upper: Option<DateTime<Utc>>) -> Box<dyn LogFilter> {
- 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<Utc>) -> Box<dyn LogFilter> {
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<DateTime<Utc>>, upper: Option<DateTime<Utc>>) -> Box<dyn LogFilter> {
+ Box::new(TimeFilter(lower, upper, false))
+}
+
+/// Like [`after`][after], but ignores the file name for date calculations.
+pub fn log_after(when: DateTime<Utc>) -> Box<dyn LogFilter> {
+ log_time(Some(when), None)
+}
+
+/// Like [`before`][before], but ignores the file name for date calculations.
+pub fn log_before(when: DateTime<Utc>) -> Box<dyn LogFilter> {
+ log_time(None, Some(when))
+}
+
#[cfg(test)]
mod tests {
use super::*;