blob: b939c46bcdb7d81f2cbc78f419db1eb18db29755 [file] [log] [blame]
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +01001// Copyright (c) 2013 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/chromeos/drive/logging.h"
6
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01007#include <stdarg.h> // va_list
Ben Murdochbb1529c2013-08-08 10:24:53 +01008#include <string>
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01009
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010010#include "base/lazy_instance.h"
Torne (Richard Coles)5e3f23d2013-06-11 16:24:11 +010011#include "base/strings/stringprintf.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010012#include "chrome/browser/drive/event_logger.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010013
14namespace drive {
15namespace util {
16namespace {
17
Ben Murdocheb525c52013-07-10 11:40:50 +010018static base::LazyInstance<EventLogger> g_logger =
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010019 LAZY_INSTANCE_INITIALIZER;
20
21} // namespace
22
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010023void Log(logging::LogSeverity severity, const char* format, ...) {
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010024 std::string what;
25
26 va_list args;
27 va_start(args, format);
28 base::StringAppendV(&what, format, args);
29 va_end(args);
30
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010031 DVLOG(1) << what;
32
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010033 // On thread-safety: LazyInstance guarantees thread-safety for the object
34 // creation. EventLogger::Log() internally maintains the lock.
Ben Murdocheb525c52013-07-10 11:40:50 +010035 EventLogger* ptr = g_logger.Pointer();
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010036 ptr->Log(severity, what);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010037}
38
Ben Murdocheb525c52013-07-10 11:40:50 +010039std::vector<EventLogger::Event> GetLogHistory() {
40 EventLogger* ptr = g_logger.Pointer();
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010041 return ptr->GetHistory();
42}
43
44} // namespace util
45} // namespace drive