Repository navigation
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.
Read challenging. IIRC it could be generally neg_level_for or negtive_level_for?
There was a problem hiding this comment.
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.
Maybe level_excluding, level_for_excluding?
There was a problem hiding this comment.
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.
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
left a comment
There was a problem hiding this comment.
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.
Bikeshedding - this should be logically matched ^ self.not 🤣
There was a problem hiding this comment.
Yes. I did intended. It help my brain be sane. XD
No description provided.