-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
borney
committed
Jun 2, 2023
1 parent
32fa623
commit 68c3214
Showing
7 changed files
with
50 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,28 @@ | ||
use crate::filter::Filter; | ||
use crate::log::{Level, Log}; | ||
use async_trait::async_trait; | ||
use std::sync::Arc; | ||
|
||
pub(crate) struct LevelFilter { | ||
filter: Option<Arc<dyn Filter>>, | ||
level: Level, | ||
} | ||
|
||
impl LevelFilter { | ||
#[allow(dead_code)] | ||
pub(crate) fn new(level: Level, filter: Option<Arc<dyn Filter>>) -> Self { | ||
Self { level, filter } | ||
pub(crate) fn new(level: Level) -> Self { | ||
Self { level } | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Filter for LevelFilter { | ||
async fn filter(&self, mut log: Log) -> Option<Log> { | ||
if let Some(f) = &self.filter { | ||
let f = Arc::clone(f); | ||
if let Some(r) = f.filter(log).await { | ||
log = r; | ||
} else { | ||
return None; | ||
} | ||
} | ||
|
||
async fn filter(&self, log: &Log) -> bool { | ||
use std::str::FromStr; | ||
|
||
if let Ok(level) = Level::from_str(&log.level) { | ||
if level >= self.level { | ||
Some(log) | ||
} else { | ||
None | ||
return false; | ||
} | ||
} else { | ||
None | ||
} | ||
true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters