Skip to content

Commit

Permalink
chore: rename MaxFilter to LevelFilter (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
andylokandy authored Aug 2, 2024
1 parent eebc2fe commit 4e249e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions src/filter/min_level.rs → src/filter/level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use log::LevelFilter;
use log::Metadata;

use crate::filter::Filter;
Expand All @@ -28,13 +27,13 @@ use crate::filter::FilterResult;
/// - `Debug`
/// - `Trace`
///
/// If MaxLevel is set to `Info`, it will allow `Error`, `Warn`, and `Info` logs.
/// If LevelFilter is set to `Info`, it will allow `Error`, `Warn`, and `Info` logs.
///
/// If MaxLevel is set to `Off`, it will reject all logs.
/// If LevelFilter is set to `Off`, it will reject all logs.
#[derive(Debug, Clone)]
pub struct MaxLevel(pub LevelFilter);
pub struct LevelFilter(pub log::LevelFilter);

impl MaxLevel {
impl LevelFilter {
pub(crate) fn filter(&self, metadata: &Metadata) -> FilterResult {
let level = metadata.level();
if level <= self.0 {
Expand All @@ -44,14 +43,15 @@ impl MaxLevel {
}
}
}
impl From<MaxLevel> for Filter {
fn from(filter: MaxLevel) -> Self {
Filter::MaxLevel(filter)
}
}

impl From<LevelFilter> for Filter {
fn from(filter: LevelFilter) -> Self {
Filter::MaxLevel(MaxLevel(filter))
Filter::Level(filter)
}
}

impl From<log::LevelFilter> for Filter {
fn from(filter: log::LevelFilter) -> Self {
Filter::Level(LevelFilter(filter))
}
}
8 changes: 4 additions & 4 deletions src/filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
// limitations under the License.

pub use self::custom::CustomFilter;
pub use self::min_level::MaxLevel;
pub use self::level::LevelFilter;

mod custom;
mod min_level;
mod level;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FilterResult {
Expand All @@ -30,14 +30,14 @@ pub enum FilterResult {

#[derive(Debug)]
pub enum Filter {
MaxLevel(MaxLevel),
Level(LevelFilter),
Custom(CustomFilter),
}

impl Filter {
pub(crate) fn filter(&self, metadata: &log::Metadata) -> FilterResult {
match self {
Filter::MaxLevel(filter) => filter.filter(metadata),
Filter::Level(filter) => filter.filter(metadata),
Filter::Custom(filter) => filter.filter(metadata),
}
}
Expand Down

0 comments on commit 4e249e0

Please sign in to comment.