1 // Copyright 2020 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.
4
5 #include "chrome/browser/nearby_sharing/logging/logging.h"
6 #include "chrome/browser/nearby_sharing/logging/log_buffer.h"
7
ScopedLogMessage(const char * file,int line,logging::LogSeverity severity)8 ScopedLogMessage::ScopedLogMessage(const char* file,
9 int line,
10 logging::LogSeverity severity)
11 : file_(file), line_(line), severity_(severity) {}
12
~ScopedLogMessage()13 ScopedLogMessage::~ScopedLogMessage() {
14 const std::string string_from_stream = stream_.str();
15 LogBuffer::GetInstance()->AddLogMessage(LogBuffer::LogMessage(
16 string_from_stream, base::Time::Now(), file_, line_, severity_));
17
18 // Don't emit VERBOSE-level logging to the standard logging system unless
19 // verbose logging is enabled for the source file.
20 if (severity_ <= logging::LOG_VERBOSE &&
21 logging::GetVlogLevelHelper(file_, strlen(file_) + 1) <= 0) {
22 return;
23 }
24
25 // The destructor of |log_message| also creates a log for the standard logging
26 // system.
27 logging::LogMessage log_message(file_, line_, severity_);
28 log_message.stream() << string_from_stream;
29 }
30