Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: rename MaxFilter to LevelFilter #23

Merged
merged 2 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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