Skip to content
Snippets Groups Projects
Commit 0fa95eab authored by Sree Kuchibhotla's avatar Sree Kuchibhotla
Browse files

Ability to filter log messages based on log level

parent 64f10281
No related branches found
No related tags found
No related merge requests found
...@@ -50,6 +50,10 @@ ...@@ -50,6 +50,10 @@
#include "test/proto/metrics.grpc.pb.h" #include "test/proto/metrics.grpc.pb.h"
#include "test/proto/metrics.pb.h" #include "test/proto/metrics.pb.h"
extern "C" {
extern void gpr_default_log(gpr_log_func_args* args);
}
DEFINE_int32(metrics_port, 8081, "The metrics server port."); DEFINE_int32(metrics_port, 8081, "The metrics server port.");
DEFINE_int32(metrics_collection_interval_secs, 5, DEFINE_int32(metrics_collection_interval_secs, 5,
...@@ -94,6 +98,12 @@ DEFINE_string(test_cases, "", ...@@ -94,6 +98,12 @@ DEFINE_string(test_cases, "",
" 'large_unary', 10% of the time and 'empty_stream' the remaining" " 'large_unary', 10% of the time and 'empty_stream' the remaining"
" 70% of the time"); " 70% of the time");
DEFINE_int32(log_level, GPR_LOG_SEVERITY_DEBUG,
"Severity level of messages that should be logged. Any messages "
"greater than or equal to the level set here will be logged. "
"The choices are: 0 (GPR_LOG_SEVERITY_DEBUG), 1 "
"(GPR_LOG_SEVERITY_INFO) and 2 (GPR_LOG_SEVERITY_ERROR.");
using grpc::testing::kTestCaseList; using grpc::testing::kTestCaseList;
using grpc::testing::MetricsService; using grpc::testing::MetricsService;
using grpc::testing::MetricsServiceImpl; using grpc::testing::MetricsServiceImpl;
...@@ -102,6 +112,16 @@ using grpc::testing::TestCaseType; ...@@ -102,6 +112,16 @@ using grpc::testing::TestCaseType;
using grpc::testing::UNKNOWN_TEST; using grpc::testing::UNKNOWN_TEST;
using grpc::testing::WeightedRandomTestSelector; using grpc::testing::WeightedRandomTestSelector;
static int log_level = GPR_LOG_SEVERITY_DEBUG;
// A simple wrapper to grp_default_log() function. This only logs messages at or
// above the current log level (set in 'log_level' variable)
void TestLogFunction(gpr_log_func_args* args) {
if (args->severity >= log_level) {
gpr_default_log(args);
}
}
TestCaseType GetTestTypeFromName(const grpc::string& test_name) { TestCaseType GetTestTypeFromName(const grpc::string& test_name) {
TestCaseType test_case = UNKNOWN_TEST; TestCaseType test_case = UNKNOWN_TEST;
...@@ -190,6 +210,18 @@ void LogParameterInfo(const std::vector<grpc::string>& addresses, ...@@ -190,6 +210,18 @@ void LogParameterInfo(const std::vector<grpc::string>& addresses,
int main(int argc, char** argv) { int main(int argc, char** argv) {
grpc::testing::InitTest(&argc, &argv, true); grpc::testing::InitTest(&argc, &argv, true);
if (FLAGS_log_level > GPR_LOG_SEVERITY_ERROR ||
FLAGS_log_level < GPR_LOG_SEVERITY_DEBUG) {
gpr_log(GPR_ERROR, "log_level should be an integer between %d and %d",
GPR_LOG_SEVERITY_DEBUG, GPR_LOG_SEVERITY_ERROR);
return 1;
}
// Change the default log function to TestLogFunction which respects the
// log_level setting.
log_level = FLAGS_log_level;
gpr_set_log_function(TestLogFunction);
srand(time(NULL)); srand(time(NULL));
// Parse the server addresses // Parse the server addresses
...@@ -198,7 +230,7 @@ int main(int argc, char** argv) { ...@@ -198,7 +230,7 @@ int main(int argc, char** argv) {
// Parse test cases and weights // Parse test cases and weights
if (FLAGS_test_cases.length() == 0) { if (FLAGS_test_cases.length() == 0) {
gpr_log(GPR_INFO, "Not running tests. The 'test_cases' string is empty"); gpr_log(GPR_ERROR, "Not running tests. The 'test_cases' string is empty");
return 1; return 1;
} }
...@@ -270,6 +302,5 @@ int main(int argc, char** argv) { ...@@ -270,6 +302,5 @@ int main(int argc, char** argv) {
it->join(); it->join();
} }
metrics_server->Wait();
return 0; return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment