diff options
-rw-r--r-- | raidgrep.1.asciidoc | 8 | ||||
-rw-r--r-- | src/fexpr/grammar.lalrpop | 2 | ||||
-rw-r--r-- | src/filters/log.rs | 26 | ||||
-rw-r--r-- | src/main.rs | 2 |
4 files changed, 35 insertions, 3 deletions
diff --git a/raidgrep.1.asciidoc b/raidgrep.1.asciidoc index 65b5d18..78dcf78 100644 --- a/raidgrep.1.asciidoc +++ b/raidgrep.1.asciidoc @@ -96,6 +96,14 @@ Those predicates can be used as-is in the filter: Include logs made after the given date. See *-before* for valid date formats. +*-log-before* 'DATE', *-log-after* 'DATE':: + Same as *-before* and *-after*, but does not use file name heuristics to + filter the date. + + + + This can fix wrong results in case you renamed files, but it comes at the + cost of worse runtime performance. You should always use *-before*/*-after* + when possible! + *-boss* 'BOSSES':: Include logs from the given bosses. See below for a list of valid boss names. Names can also be comma separated. diff --git a/src/fexpr/grammar.lalrpop b/src/fexpr/grammar.lalrpop index c0165ce..55bd669 100644 --- a/src/fexpr/grammar.lalrpop +++ b/src/fexpr/grammar.lalrpop @@ -50,6 +50,8 @@ LogPredicate: Box<dyn filters::log::LogFilter> = { "-weekday" <Comma<Weekday>> => filters::log::weekday(<>), "-before" <Date> => filters::log::before(<>), "-after" <Date> => filters::log::after(<>), + "-log-before" <Date> => filters::log::log_before(<>), + "-log-after" <Date> => filters::log::log_after(<>), "-boss" <Comma<Boss>> => filters::log::boss(<>), 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::*; diff --git a/src/main.rs b/src/main.rs index ad35d20..625e869 100644 --- a/src/main.rs +++ b/src/main.rs @@ -344,7 +344,7 @@ fn maybe_save_history(rl: &Editor<()>, path: Option<&Path>) { debug!("Saving history to {:?}", path); let parent = path .parent() - .ok_or(anyhow!("Path does not have a parent"))?; + .ok_or_else(|| anyhow!("Path does not have a parent"))?; fs::create_dir_all(parent).context("Could not create directory")?; rl.save_history(path)?; Ok(()) |