-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: add TargetFilter::level_for_not #47
Conversation
|
||
/// 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 { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
let matched = metadata.target().starts_with(self.target.as_ref()); | ||
if (matched && !self.not) || (!matched && self.not) { |
There was a problem hiding this comment.
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
🤣
There was a problem hiding this comment.
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
No description provided.