Fix a bug in `absl::SetVLogLevel` where a less generic pattern incorrectly removed a more generic one.
### Example:
The user passes `--vmodule=*pipeline*=10` to enable logs in files containing `"pipeline"` in their names:
```
pipeline_a.cc
pipeline_b.cc
pipeline_c.cc
```
Additionally, `pipeline_a.cc` executes `absl::SetVlogLevel("pipeline_a", 10)`.
### Expected behavior:
VLOG level `10` is enabled in all files containing `"pipeline"` in their names. `absl::SetVlogLevel("pipeline_a", 10)` should not affect this, as `pipeline_a.cc` is already covered by `--vmodule=*pipeline*=10` and have the same level there.
### Actual behavior (before the CL):
VLOG level `10` is enabled only in `pipeline_a.cc`. `--vmodule=*pipeline*=10` is ignored.
### Reason:
`absl::SetVlogLevel` is based on `PrependVModuleLocked`. The issue lies in the following code within `PrependVModuleLocked`:
```cc
// This is a memory optimization to avoid storing patterns that will never
// match due to exit early semantics. Primarily optimized for our own unit
// tests.
get_vmodule_info().erase(
std::remove_if(++iter, get_vmodule_info().end(),
[module_pattern](const VModuleInfo& info) {
return FNMatch(info.module_pattern, module_pattern);
}),
get_vmodule_info().cend());
```
When `absl::SetVlogLevel("pipeline_a", 10)` is executed, `get_vmodule_info()` contains `"*pipeline*"`. Therefore, `info.module_pattern` equals to `"*pipeline*"` and `module_pattern` equals to `"pipeline_a"`.
Because `"pipeline_a"` matches the pattern `"*pipeline*"`, the pattern `"*pipeline*"` is erroneously erased. `get_vmodule_info()` then only contains the `"pipeline_a"` pattern.
### Solution:
This CL corrects the order of the arguments in `FNMatch` to:
```cc
FNMatch(module_pattern, info.module_pattern);
```
This ensures that it correctly checks if the new pattern is more general than the previous pattern, but not vice versa. In the example above, the new pattern `"pipeline_a"` does not match the previous `"*pipeline*"` pattern. Therefore, `get_vmodule_info()` retains both patterns in the following order: `"pipeline_a"`, `"*pipeline*"`.
PiperOrigin-RevId: 675776298
Change-Id: I9550dbd4282e66799619369894b8304856a7a777
| Name |
Last commit
|
Last Update |
|---|---|---|
| .. | ||
| BUILD.bazel | Loading commit data... | |
| append_truncated.h | Loading commit data... | |
| check_impl.h | Loading commit data... | |
| check_op.cc | Loading commit data... | |
| check_op.h | Loading commit data... | |
| conditions.cc | Loading commit data... | |
| conditions.h | Loading commit data... | |
| config.h | Loading commit data... | |
| flags.h | Loading commit data... | |
| fnmatch.cc | Loading commit data... | |
| fnmatch.h | Loading commit data... | |
| fnmatch_benchmark.cc | Loading commit data... | |
| fnmatch_test.cc | Loading commit data... | |
| globals.cc | Loading commit data... | |
| globals.h | Loading commit data... | |
| log_format.cc | Loading commit data... | |
| log_format.h | Loading commit data... | |
| log_impl.h | Loading commit data... | |
| log_message.cc | Loading commit data... | |
| log_message.h | Loading commit data... | |
| log_sink_set.cc | Loading commit data... | |
| log_sink_set.h | Loading commit data... | |
| nullguard.cc | Loading commit data... | |
| nullguard.h | Loading commit data... | |
| nullstream.h | Loading commit data... | |
| proto.cc | Loading commit data... | |
| proto.h | Loading commit data... | |
| stderr_log_sink_test.cc | Loading commit data... | |
| strip.h | Loading commit data... | |
| structured.h | Loading commit data... | |
| test_actions.cc | Loading commit data... | |
| test_actions.h | Loading commit data... | |
| test_helpers.cc | Loading commit data... | |
| test_helpers.h | Loading commit data... | |
| test_matchers.cc | Loading commit data... | |
| test_matchers.h | Loading commit data... | |
| vlog_config.cc | Loading commit data... | |
| vlog_config.h | Loading commit data... | |
| vlog_config_benchmark.cc | Loading commit data... | |
| voidify.h | Loading commit data... |