1 #include <gtest/gtest.h> 2 #include <xgboost/logging.h> 3 #include <string> 4 #include "../../../src/common/timer.h" 5 6 namespace xgboost { 7 namespace common { TEST(Monitor,Logging)8TEST(Monitor, Logging) { 9 auto run_monitor = 10 []() { 11 Monitor monitor_; 12 monitor_.Init("Monitor test"); 13 monitor_.Start("basic"); 14 monitor_.Stop("basic"); 15 }; 16 17 Args args = {std::make_pair("verbosity", "3")}; 18 ConsoleLogger::Configure(args); 19 ASSERT_EQ(ConsoleLogger::GlobalVerbosity(), ConsoleLogger::LogVerbosity::kDebug); 20 21 testing::internal::CaptureStderr(); 22 run_monitor(); 23 std::string output = testing::internal::GetCapturedStderr(); 24 ASSERT_NE(output.find("Monitor"), std::string::npos); 25 26 // Monitor only prints messages when set to DEBUG. 27 args = {std::make_pair("verbosity", "2")}; 28 ConsoleLogger::Configure(args); 29 testing::internal::CaptureStderr(); 30 run_monitor(); 31 output = testing::internal::GetCapturedStderr(); 32 ASSERT_EQ(output.size(), 0); 33 } 34 } // namespace common 35 } // namespace xgboost 36