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 |
|---|---|---|
| .. | ||
| internal | Loading commit data... | |
| BUILD.bazel | Loading commit data... | |
| CMakeLists.txt | Loading commit data... | |
| absl_check.h | Loading commit data... | |
| absl_check_test.cc | Loading commit data... | |
| absl_log.h | Loading commit data... | |
| absl_log_basic_test.cc | Loading commit data... | |
| absl_vlog_is_on.h | Loading commit data... | |
| check.h | Loading commit data... | |
| check_test.cc | Loading commit data... | |
| check_test_impl.inc | Loading commit data... | |
| die_if_null.cc | Loading commit data... | |
| die_if_null.h | Loading commit data... | |
| die_if_null_test.cc | Loading commit data... | |
| flags.cc | Loading commit data... | |
| flags.h | Loading commit data... | |
| flags_test.cc | Loading commit data... | |
| globals.cc | Loading commit data... | |
| globals.h | Loading commit data... | |
| globals_test.cc | Loading commit data... | |
| initialize.cc | Loading commit data... | |
| initialize.h | Loading commit data... | |
| log.h | Loading commit data... | |
| log_basic_test.cc | Loading commit data... | |
| log_basic_test_impl.inc | Loading commit data... | |
| log_benchmark.cc | Loading commit data... | |
| log_entry.cc | Loading commit data... | |
| log_entry.h | Loading commit data... | |
| log_entry_test.cc | Loading commit data... | |
| log_format_test.cc | Loading commit data... | |
| log_macro_hygiene_test.cc | Loading commit data... | |
| log_modifier_methods_test.cc | Loading commit data... | |
| log_sink.cc | Loading commit data... | |
| log_sink.h | Loading commit data... | |
| log_sink_registry.h | Loading commit data... | |
| log_sink_test.cc | Loading commit data... | |
| log_streamer.h | Loading commit data... | |
| log_streamer_test.cc | Loading commit data... | |
| scoped_mock_log.cc | Loading commit data... | |
| scoped_mock_log.h | Loading commit data... | |
| scoped_mock_log_test.cc | Loading commit data... | |
| stripping_test.cc | Loading commit data... | |
| structured.h | Loading commit data... | |
| structured_test.cc | Loading commit data... | |
| vlog_is_on.h | Loading commit data... | |
| vlog_is_on_test.cc | Loading commit data... |