Skip to content

feat: add TargetFilter::level_for_not - #47

Merged
andylokandy merged 3 commits into
fast:mainfrom
andylokandy:dev3
Aug 14, 2024
Merged

andylokandy merged 3 commits into
fast:mainfrom
andylokandy:dev3

Conversation

@andylokandy

@andylokandy andylokandy commented Aug 14, 2024 •

Copy link
Copy Markdown
Contributor

No description provided.

@andylokandy
andylokandy requested a review from tisonkun August 14, 2024 08:39
Comment thread src/filter/target.rs

/// The filter will be applied only if the target **does not have** a prefix that matches the
/// target of the log record,
pub fn level_for_not(target: impl Into<Cow<'static, str>>, level: log::LevelFilter) -> Self {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read challenging. IIRC it could be generally neg_level_for or negtive_level_for?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not negative on level but negative on for. So I'd like to put not word after for.

@andylokandy andylokandy Aug 14, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe level_excluding, level_for_excluding?

@andylokandy andylokandy Aug 14, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In practice, it is like:

let dispatch = Dispatch::new()
    // discard other targets
    .filter(TargetFilter::level_for_not(
        "databend::log::structlog",
        LevelFilter::Off,
    ))
    .append(structlog_log_file);
logger = logger.dispatch(dispatch);

@tisonkun tisonkun Aug 14, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to:

pub fn negative(mut self, negative: bool) -> Self {
  self.negative = negative;
  self
}

Maybe name it not, I'm OK with it. But the pattern is to invert the matching result manually in a fluent method. What do you think?

@tisonkun tisonkun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example looks reasonable. I'm OK with either way now. You make the final call and let's try it out.

@andylokandy
andylokandy merged commit 8fd1f34 into fast:main Aug 14, 2024
@andylokandy
andylokandy deleted the dev3 branch August 14, 2024 10:10
Comment thread src/filter/target.rs
Comment on lines +53 to +54
let matched = metadata.target().starts_with(self.target.as_ref());
if (matched && !self.not) || (!matched && self.not) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bikeshedding - this should be logically matched ^ self.not 🤣

@andylokandy andylokandy Aug 14, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I did intended. It help my brain be sane. XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants