Index: components/proximity_auth/logging/logging_unittest.cc |
diff --git a/components/proximity_auth/logging/logging_unittest.cc b/components/proximity_auth/logging/logging_unittest.cc |
index 9efc5d7f7a5530fb2217d93d3e003b54dbaecf06..d06c550cd195055e7c439a55f8ac6666290ea97c 100644 |
--- a/components/proximity_auth/logging/logging_unittest.cc |
+++ b/components/proximity_auth/logging/logging_unittest.cc |
@@ -7,6 +7,7 @@ |
#include <stddef.h> |
#include "base/lazy_instance.h" |
+#include "base/memory/ptr_util.h" |
#include "base/numerics/safe_conversions.h" |
#include "base/strings/string_number_conversions.h" |
#include "components/proximity_auth/logging/log_buffer.h" |
@@ -21,36 +22,34 @@ const char kLog2[] = "Construction grade cedar"; |
const char kLog3[] = "Pine infested by hungry beetles"; |
// Called for every log message added to the standard logging system. The new |
-// log is saved in |g_standard_logs| and consumed so it does not flood stdout. |
+// log is saved in |g_standard_logs|. |
base::LazyInstance<std::vector<std::string>> g_standard_logs = |
LAZY_INSTANCE_INITIALIZER; |
-bool HandleStandardLogMessage(int severity, |
- const char* file, |
- int line, |
- size_t message_start, |
- const std::string& str) { |
- g_standard_logs.Get().push_back(str); |
- return true; |
-} |
+class StandardLogMessageListener : logging::LogMessageListener { |
+ void OnMessage(int severity, |
+ const char* file, |
+ int line, |
+ size_t message_start, |
+ const std::string& str) override { |
+ g_standard_logs.Get().push_back(str); |
+ } |
+}; |
} // namespace |
class ProximityAuthLoggingTest : public testing::Test { |
public: |
- ProximityAuthLoggingTest() : previous_handler_(NULL) {} |
- |
void SetUp() override { |
LogBuffer::GetInstance()->Clear(); |
g_standard_logs.Get().clear(); |
- previous_handler_ = logging::GetLogMessageHandler(); |
- logging::SetLogMessageHandler(&HandleStandardLogMessage); |
+ log_listener_ = base::MakeUnique<StandardLogMessageListener>(); |
} |
- void TearDown() override { logging::SetLogMessageHandler(previous_handler_); } |
+ void TearDown() override { log_listener_.reset(); } |
private: |
- logging::LogMessageHandlerFunction previous_handler_; |
+ std::unique_ptr<StandardLogMessageListener> log_listener_; |
}; |
TEST_F(ProximityAuthLoggingTest, LogsSavedToBuffer) { |