1 // Copyright (c) 2012 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 "chrome/browser/drive/event_logger.h"
7 #include "base/logging.h"
8 #include "base/strings/stringprintf.h"
12 EventLogger::Event::Event(
13 int id
, logging::LogSeverity severity
, const std::string
& what
)
16 when(base::Time::Now()),
20 EventLogger::EventLogger()
21 : history_size_(kDefaultHistorySize
),
25 EventLogger::~EventLogger() {
28 void EventLogger::LogRawString(logging::LogSeverity severity
,
29 const std::string
& what
) {
30 base::AutoLock
auto_lock(lock_
);
31 history_
.push_back(Event(next_event_id_
, severity
, what
));
33 if (history_
.size() > history_size_
)
37 void EventLogger::Log(logging::LogSeverity severity
, const char* format
, ...) {
41 va_start(args
, format
);
42 base::StringAppendV(&what
, format
, args
);
46 LogRawString(severity
, what
);
49 void EventLogger::SetHistorySize(size_t history_size
) {
50 base::AutoLock
auto_lock(lock_
);
52 history_size_
= history_size
;
55 std::vector
<EventLogger::Event
> EventLogger::GetHistory() {
56 base::AutoLock
auto_lock(lock_
);
57 std::vector
<Event
> output
;
58 output
.assign(history_
.begin(), history_
.end());