1 // Copyright 2015 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 "components/proximity_auth/logging/log_buffer.h"
7 #include "base/lazy_instance.h"
9 namespace proximity_auth
{
13 // The maximum number of logs that can be stored in the buffer.
14 const size_t kMaxBufferSize
= 1000;
16 // The global instance returned by LogBuffer::GetInstance().
17 base::LazyInstance
<LogBuffer
>::Leaky g_log_buffer
= LAZY_INSTANCE_INITIALIZER
;
21 LogBuffer::LogMessage::LogMessage(const std::string
& text
,
22 const base::Time
& time
,
23 const std::string
& file
,
25 logging::LogSeverity severity
)
26 : text(text
), time(time
), file(file
), line(line
), severity(severity
) {
29 LogBuffer::LogBuffer() {
32 LogBuffer::~LogBuffer() {
36 LogBuffer
* LogBuffer::GetInstance() {
37 return &g_log_buffer
.Get();
40 void LogBuffer::AddLogMessage(const LogMessage
& log_message
) {
41 // Note: We may want to sort the messages by timestamp if there are cases
42 // where logs are not added chronologically.
43 log_messages_
.push_back(log_message
);
44 if (log_messages_
.size() > MaxBufferSize())
45 log_messages_
.pop_front();
48 void LogBuffer::Clear() {
49 log_messages_
.clear();
52 size_t LogBuffer::MaxBufferSize() const {
53 return kMaxBufferSize
;