| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/drive/event_logger.h" | 5 #include "chrome/browser/drive/event_logger.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 | 9 |
| 10 namespace drive { | 10 namespace drive { |
| 11 | 11 |
| 12 EventLogger::Event::Event(int id, const std::string& what) | 12 EventLogger::Event::Event( |
| 13 int id, logging::LogSeverity severity, const std::string& what) |
| 13 : id(id), | 14 : id(id), |
| 15 severity(severity), |
| 14 when(base::Time::Now()), | 16 when(base::Time::Now()), |
| 15 what(what) { | 17 what(what) { |
| 16 } | 18 } |
| 17 | 19 |
| 18 EventLogger::EventLogger() | 20 EventLogger::EventLogger() |
| 19 : history_size_(kDefaultHistorySize), | 21 : history_size_(kDefaultHistorySize), |
| 20 next_event_id_(0) { | 22 next_event_id_(0) { |
| 21 } | 23 } |
| 22 | 24 |
| 23 EventLogger::~EventLogger() { | 25 EventLogger::~EventLogger() { |
| 24 } | 26 } |
| 25 | 27 |
| 26 void EventLogger::Log(const char* format, ...) { | 28 void EventLogger::Log(logging::LogSeverity severity, const std::string& what) { |
| 27 std::string what; | |
| 28 | |
| 29 va_list args; | |
| 30 va_start(args, format); | |
| 31 base::StringAppendV(&what, format, args); | |
| 32 va_end(args); | |
| 33 | |
| 34 DVLOG(1) << what; | |
| 35 | |
| 36 base::AutoLock auto_lock(lock_); | 29 base::AutoLock auto_lock(lock_); |
| 37 history_.push_back(Event(next_event_id_, what)); | 30 history_.push_back(Event(next_event_id_, severity, what)); |
| 38 ++next_event_id_; | 31 ++next_event_id_; |
| 39 if (history_.size() > history_size_) | 32 if (history_.size() > history_size_) |
| 40 history_.pop_front(); | 33 history_.pop_front(); |
| 41 } | 34 } |
| 42 | 35 |
| 43 void EventLogger::SetHistorySize(size_t history_size) { | 36 void EventLogger::SetHistorySize(size_t history_size) { |
| 44 base::AutoLock auto_lock(lock_); | 37 base::AutoLock auto_lock(lock_); |
| 45 history_.clear(); | 38 history_.clear(); |
| 46 history_size_ = history_size; | 39 history_size_ = history_size; |
| 47 } | 40 } |
| 48 | 41 |
| 49 std::vector<EventLogger::Event> EventLogger::GetHistory() { | 42 std::vector<EventLogger::Event> EventLogger::GetHistory() { |
| 50 base::AutoLock auto_lock(lock_); | 43 base::AutoLock auto_lock(lock_); |
| 51 std::vector<Event> output; | 44 std::vector<Event> output; |
| 52 output.assign(history_.begin(), history_.end()); | 45 output.assign(history_.begin(), history_.end()); |
| 53 return output; | 46 return output; |
| 54 } | 47 } |
| 55 | 48 |
| 56 | 49 |
| 57 } // namespace drive | 50 } // namespace drive |
| OLD | NEW |