[no_logging] Restrict regexes by module name (#33468)

Promised follow-up to #33444
pull/33470/head
Craig Tiller 1 year ago committed by GitHub
parent cb9fe64fa5
commit 23f5810264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      test/core/end2end/tests/no_logging.cc

@ -17,11 +17,14 @@
//
#include <atomic>
#include <map>
#include <regex>
#include <string>
#include <utility>
#include <vector>
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "gtest/gtest.h"
@ -69,8 +72,21 @@ class Verifier {
static void DispatchLog(gpr_log_func_args* args) { g_log_func_.load()(args); }
static void NoLog(gpr_log_func_args* args) {
static const auto* const re = new std::regex("^Verify .* for [0-9]+ms");
if (std::regex_match(args->message, *re)) {
static const auto* const allowed_logs_by_module =
new std::map<absl::string_view, std::regex>(
{{"cq_verifier.cc", std::regex("^Verify .* for [0-9]+ms")}});
absl::string_view filename = args->file;
auto slash = filename.rfind('/');
if (slash != absl::string_view::npos) {
filename = filename.substr(slash + 1);
}
slash = filename.rfind('\\');
if (slash != absl::string_view::npos) {
filename = filename.substr(slash + 1);
}
auto it = allowed_logs_by_module->find(filename);
if (it != allowed_logs_by_module->end() &&
std::regex_match(args->message, it->second)) {
gpr_default_log(args);
return;
}

Loading…
Cancel
Save