1 // Copyright 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.
5 #include "chrome/browser/sync_file_system/logger.h"
7 #include "base/files/file_util.h"
8 #include "base/lazy_instance.h"
9 #include "base/location.h"
10 #include "base/strings/stringprintf.h"
11 #include "chrome/browser/drive/event_logger.h"
13 namespace sync_file_system
{
17 static base::LazyInstance
<drive::EventLogger
> g_logger
=
18 LAZY_INSTANCE_INITIALIZER
;
20 const char* LogSeverityToString(logging::LogSeverity level
) {
22 case logging::LOG_ERROR
:
24 case logging::LOG_WARNING
:
26 case logging::LOG_INFO
:
28 case logging::LOG_VERBOSE
:
33 return "Unknown Log Severity";
39 g_logger
.Pointer()->SetHistorySize(drive::kDefaultHistorySize
);
42 void Log(logging::LogSeverity severity
,
43 const tracked_objects::Location
& location
,
49 va_start(args
, format
);
50 base::StringAppendV(&what
, format
, args
);
53 // Log to WebUI regardless of LogSeverity (e.g. ignores command line flags).
54 // On thread-safety: LazyInstance guarantees thread-safety for the object
55 // creation. EventLogger::Log() internally maintains the lock.
56 drive::EventLogger
* ptr
= g_logger
.Pointer();
57 ptr
->LogRawString(severity
, base::StringPrintf("[%s] %s",
58 LogSeverityToString(severity
),
61 // Log to console if the severity is at or above the min level.
62 // LOG_VERBOSE logs are also output if the verbosity of this module
63 // (sync_file_system/logger) is >= 1.
64 // TODO(kinuko,calvinlo): Reconsider this logging hack, it's not recommended
65 // to directly use LogMessage.
66 if (severity
< logging::GetMinLogLevel() && !VLOG_IS_ON(1))
68 logging::LogMessage(location
.file_name(), location
.line_number(), severity
)
72 std::vector
<drive::EventLogger::Event
> GetLogHistory() {
73 drive::EventLogger
* ptr
= g_logger
.Pointer();
74 return ptr
->GetHistory();
78 } // namespace sync_file_system