This source file includes following definitions.
- StartCapturingLogs
- StopCapturingLogs
- LogMessageHandler
#include "net/test/scoped_mock_log.h"
#include "base/logging.h"
namespace net {
namespace test {
ScopedMockLog* ScopedMockLog::g_instance_ = NULL;
ScopedMockLog::ScopedMockLog() : is_capturing_logs_(false) {}
ScopedMockLog::~ScopedMockLog() {
if (is_capturing_logs_) {
StopCapturingLogs();
}
}
void ScopedMockLog::StartCapturingLogs() {
RAW_CHECK(!is_capturing_logs_);
RAW_CHECK(!g_instance_);
is_capturing_logs_ = true;
g_instance_ = this;
previous_handler_ = logging::GetLogMessageHandler();
logging::SetLogMessageHandler(LogMessageHandler);
}
void ScopedMockLog::StopCapturingLogs() {
RAW_CHECK(is_capturing_logs_);
RAW_CHECK(g_instance_ == this);
is_capturing_logs_ = false;
logging::SetLogMessageHandler(previous_handler_);
g_instance_ = NULL;
}
bool ScopedMockLog::LogMessageHandler(int severity,
const char* file,
int line,
size_t message_start,
const std::string& str) {
return g_instance_->Log(severity, file, line, message_start, str);
}
}
}