1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/test/scoped_mock_log.h"
7 #include "base/logging.h"
13 ScopedMockLog
* ScopedMockLog::g_instance_
= NULL
;
15 ScopedMockLog::ScopedMockLog() : is_capturing_logs_(false) {}
17 ScopedMockLog::~ScopedMockLog() {
18 if (is_capturing_logs_
) {
23 void ScopedMockLog::StartCapturingLogs() {
24 // We don't use CHECK(), which can generate a new LOG message, and
25 // thus can confuse ScopedMockLog objects or other registered
27 RAW_CHECK(!is_capturing_logs_
);
28 RAW_CHECK(!g_instance_
);
30 is_capturing_logs_
= true;
32 previous_handler_
= logging::GetLogMessageHandler();
33 logging::SetLogMessageHandler(LogMessageHandler
);
36 void ScopedMockLog::StopCapturingLogs() {
37 // We don't use CHECK(), which can generate a new LOG message, and
38 // thus can confuse ScopedMockLog objects or other registered
40 RAW_CHECK(is_capturing_logs_
);
41 RAW_CHECK(g_instance_
== this);
43 is_capturing_logs_
= false;
44 logging::SetLogMessageHandler(previous_handler_
);
49 bool ScopedMockLog::LogMessageHandler(int severity
,
53 const std::string
& str
) {
54 return g_instance_
->Log(severity
, file
, line
, message_start
, str
);