Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(698)

Side by Side Diff: chrome/browser/sync_file_system/logger.cc

Issue 15657002: Mirror syncfs log to console and WebUI, with LogSeverity support. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added tests Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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/sync_file_system/logger.h" 5 #include "chrome/browser/sync_file_system/logger.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/stringprintf.h" 8 #include "base/stringprintf.h"
9 #include "chrome/browser/google_apis/event_logger.h" 9 #include "chrome/browser/google_apis/event_logger.h"
10 10
11 namespace sync_file_system { 11 namespace sync_file_system {
12 namespace util { 12 namespace util {
13 namespace { 13 namespace {
14 14
15 static base::LazyInstance<google_apis::EventLogger> g_logger = 15 static base::LazyInstance<google_apis::EventLogger> g_logger =
16 LAZY_INSTANCE_INITIALIZER; 16 LAZY_INSTANCE_INITIALIZER;
17 17
18 std::string LogSeverityToString(logging::LogSeverity level) {
19 switch (level) {
20 case logging::LOG_ERROR:
21 return "Error";
22 case logging::LOG_WARNING:
23 return "Warning";
24 case logging::LOG_INFO:
25 return "Info";
26 }
27
28 NOTREACHED();
29 return "Unknown Log Severity";
30 }
31
32 // Need helper function since the LOG macro can't handle argument values.
33 void LogToConsole(logging::LogSeverity level, std::string log_event) {
tzik 2013/05/22 09:30:54 const ref?
calvinlo 2013/05/23 10:00:15 Done.
34 switch (level) {
35 case logging::LOG_ERROR:
36 LOG(ERROR) << log_event;
37 return;
38 case logging::LOG_WARNING:
39 LOG(WARNING) << log_event;
40 return;
41 case logging::LOG_INFO:
42 LOG(INFO) << log_event;
43 return;
44 }
45
46 LOG(FATAL) << "LogToConsole() missing case for LogSeverity=" << level;
47 NOTREACHED();
48 }
49
18 } // namespace 50 } // namespace
19 51
20 void Log(const char* format, ...) { 52 // Static
nhiroki 2013/05/22 09:18:24 nit: I think you don't have to add "Static" commen
calvinlo 2013/05/23 10:00:15 Done.
53 void ClearLog() {
54 g_logger.Pointer()->SetHistorySize(google_apis::kDefaultHistorySize);
55 }
56
57 // Static
nhiroki 2013/05/22 09:18:24 ditto.
calvinlo 2013/05/23 10:00:15 Done.
58 void Log(logging::LogSeverity level, const char* format, ...) {
59 // Ignore log if level is not high enough.
60 if (level < logging::GetMinLogLevel())
61 return;
62
21 std::string what; 63 std::string what;
22 64
23 va_list args; 65 va_list args;
24 va_start(args, format); 66 va_start(args, format);
25 base::StringAppendV(&what, format, args); 67 base::StringAppendV(&what, format, args);
26 va_end(args); 68 va_end(args);
27 69
28 // On thread-safety: LazyInstance guarantees thread-safety for the object 70 // On thread-safety: LazyInstance guarantees thread-safety for the object
29 // creation. EventLogger::Log() internally maintains the lock. 71 // creation. EventLogger::Log() internally maintains the lock.
30 google_apis::EventLogger* ptr = g_logger.Pointer(); 72 google_apis::EventLogger* ptr = g_logger.Pointer();
31 ptr->Log("%s", what.c_str()); 73 std::string level_string = "[" + LogSeverityToString(level) + "] ";
74 ptr->Log("%s", (level_string + what).c_str());
tzik 2013/05/22 09:35:56 Not needed in this CL, but can we add non-format v
calvinlo 2013/05/23 10:00:15 Ok thanks for explaining this offline. I will try
75
76 // Mirror log to console just in case syncfs-internals page crashes.
77 LogToConsole(level, what);
32 } 78 }
33 79
80 // Static
nhiroki 2013/05/22 09:18:24 ditto.
calvinlo 2013/05/23 10:00:15 Done.
34 std::vector<google_apis::EventLogger::Event> GetLogHistory() { 81 std::vector<google_apis::EventLogger::Event> GetLogHistory() {
35 google_apis::EventLogger* ptr = g_logger.Pointer(); 82 google_apis::EventLogger* ptr = g_logger.Pointer();
36 return ptr->GetHistory(); 83 return ptr->GetHistory();
37 } 84 }
38 85
39 } // namespace util 86 } // namespace util
40 } // namespace sync_file_system 87 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698