[email protected] | 3b33bd211 | 2012-11-14 10:59:33 | [diff] [blame] | 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. |
| 4 | |
lukasza | 8acc4eb | 2015-07-20 20:57:20 | [diff] [blame] | 5 | #include "components/drive/event_logger.h" |
[email protected] | 3b33bd211 | 2012-11-14 10:59:33 | [diff] [blame] | 6 | |
[email protected] | 4c51123 | 2013-07-24 17:18:52 | [diff] [blame] | 7 | #include "base/logging.h" |
[email protected] | d883056 | 2013-06-10 22:01:54 | [diff] [blame] | 8 | #include "base/strings/stringprintf.h" |
[email protected] | 76de6d1c | 2013-04-19 03:50:17 | [diff] [blame] | 9 | |
[email protected] | e50af765 | 2013-06-20 06:39:31 | [diff] [blame] | 10 | namespace drive { |
[email protected] | 3b33bd211 | 2012-11-14 10:59:33 | [diff] [blame] | 11 | |
[email protected] | 83d9d63 | 2013-08-01 11:47:13 | [diff] [blame] | 12 | EventLogger::Event::Event( |
| 13 | int id, logging::LogSeverity severity, const std::string& what) |
[email protected] | 3b33bd211 | 2012-11-14 10:59:33 | [diff] [blame] | 14 | : id(id), |
[email protected] | 83d9d63 | 2013-08-01 11:47:13 | [diff] [blame] | 15 | severity(severity), |
[email protected] | 3b33bd211 | 2012-11-14 10:59:33 | [diff] [blame] | 16 | when(base::Time::Now()), |
| 17 | what(what) { |
| 18 | } |
| 19 | |
[email protected] | 0cd6c7f | 2013-04-24 05:27:02 | [diff] [blame] | 20 | EventLogger::EventLogger() |
| 21 | : history_size_(kDefaultHistorySize), |
[email protected] | 3b33bd211 | 2012-11-14 10:59:33 | [diff] [blame] | 22 | next_event_id_(0) { |
| 23 | } |
| 24 | |
| 25 | EventLogger::~EventLogger() { |
| 26 | } |
| 27 | |
[email protected] | 9475cc7 | 2014-02-05 01:50:57 | [diff] [blame] | 28 | void EventLogger::LogRawString(logging::LogSeverity severity, |
| 29 | const std::string& what) { |
[email protected] | 0cd6c7f | 2013-04-24 05:27:02 | [diff] [blame] | 30 | base::AutoLock auto_lock(lock_); |
[email protected] | 83d9d63 | 2013-08-01 11:47:13 | [diff] [blame] | 31 | history_.push_back(Event(next_event_id_, severity, what)); |
[email protected] | 3b33bd211 | 2012-11-14 10:59:33 | [diff] [blame] | 32 | ++next_event_id_; |
| 33 | if (history_.size() > history_size_) |
| 34 | history_.pop_front(); |
| 35 | } |
| 36 | |
[email protected] | 9475cc7 | 2014-02-05 01:50:57 | [diff] [blame] | 37 | void EventLogger::Log(logging::LogSeverity severity, const char* format, ...) { |
| 38 | std::string what; |
| 39 | |
| 40 | va_list args; |
| 41 | va_start(args, format); |
| 42 | base::StringAppendV(&what, format, args); |
| 43 | va_end(args); |
| 44 | |
| 45 | DVLOG(1) << what; |
| 46 | LogRawString(severity, what); |
| 47 | } |
| 48 | |
[email protected] | 0cd6c7f | 2013-04-24 05:27:02 | [diff] [blame] | 49 | void EventLogger::SetHistorySize(size_t history_size) { |
| 50 | base::AutoLock auto_lock(lock_); |
| 51 | history_.clear(); |
| 52 | history_size_ = history_size; |
| 53 | } |
| 54 | |
| 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()); |
| 59 | return output; |
| 60 | } |
| 61 | |
| 62 | |
[email protected] | e50af765 | 2013-06-20 06:39:31 | [diff] [blame] | 63 | } // namespace drive |