Check if a log line's level meets the minimum level threshold. Empty `min_level` means no filtering (all levels pass).
(log_level: &str, min_level: &str)
| 732 | /// Check if a log line's level meets the minimum level threshold. |
| 733 | /// Empty `min_level` means no filtering (all levels pass). |
| 734 | pub(super) fn level_matches(log_level: &str, min_level: &str) -> bool { |
| 735 | if min_level.is_empty() { |
| 736 | return true; |
| 737 | } |
| 738 | let to_num = |s: &str| match s.to_uppercase().as_str() { |
| 739 | "ERROR" => 0, |
| 740 | "WARN" => 1, |
| 741 | "INFO" | "OCSF" => 2, |
| 742 | "DEBUG" => 3, |
| 743 | "TRACE" => 4, |
| 744 | _ => 5, // unknown levels always pass |
| 745 | }; |
| 746 | to_num(log_level) <= to_num(min_level) |
| 747 | } |
| 748 | |
| 749 | // --------------------------------------------------------------------------- |
| 750 | // Tests |
no test coverage detected