2.1 KiB
name, group, category, update-time, description, key-word
| name | group | category | update-time | description | key-word | ||||
|---|---|---|---|---|---|---|---|---|---|
| level-at-least | api | filtering | 20260512 | Create a reusable record predicate that keeps records at or above a minimum level. |
|
Level-at-least
Create a RecordPredicate that returns true when a record level is greater than or equal to a minimum threshold. This is the main helper for severity-based filtering.
Interface
pub fn level_at_least(min_level : Level) -> RecordPredicate {}
input
min_level : Level- The lowest level that should remain enabled.
output
RecordPredicate- Predicate that keeps records whosepriority()is at least the given minimum.
Explanation
Detailed rules explaining key parameters and behaviors
- Matching is based on
Level::priority(), not string comparison. - Records at the exact same level as
min_levelare included. - This helper is useful when a sink or child logger needs a stricter threshold than the parent logger.
- It composes cleanly with
all_of(...)andany_of(...).
How to Use
Here are some specific examples provided.
When Keep Warnings And Errors
When a logger should keep only important records:
let logger = Logger::new(console_sink())
.with_filter(level_at_least(Level::Warn))
In this example, Warn and Error records continue through the filter.
When Combine With Target Routing
When both severity and namespace matter:
let predicate = all_of([
target_has_prefix("service.api"),
level_at_least(Level::Info),
])
In this example, the predicate can be reused by multiple loggers or sinks.
Error Case
e.g.:
-
If
min_levelisLevel::Trace, the predicate effectively allows all normal log records. -
If
min_levelis higher than the record level, the predicate returnsfalsewithout modifying the record.
Notes
-
Use this helper when you want filtering logic to remain explicit instead of embedding level checks inline.
-
This predicate is separate from a logger's own
min_level, so both can be combined.