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

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: Rebase 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/file_util.h"
7 #include "base/lazy_instance.h" 8 #include "base/lazy_instance.h"
9 #include "base/location.h"
8 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
9 #include "chrome/browser/google_apis/event_logger.h" 11 #include "chrome/browser/google_apis/event_logger.h"
10 12
11 namespace sync_file_system { 13 namespace sync_file_system {
12 namespace util { 14 namespace util {
13 namespace { 15 namespace {
14 16
15 static base::LazyInstance<google_apis::EventLogger> g_logger = 17 static base::LazyInstance<google_apis::EventLogger> g_logger =
16 LAZY_INSTANCE_INITIALIZER; 18 LAZY_INSTANCE_INITIALIZER;
17 19
20 std::string LogSeverityToString(logging::LogSeverity level) {
21 switch (level) {
22 case logging::LOG_ERROR:
23 return "ERROR";
24 case logging::LOG_WARNING:
25 return "WARNING";
26 case logging::LOG_INFO:
27 return "INFO";
28 }
29
30 NOTREACHED();
31 return "Unknown Log Severity";
32 }
33
34 void LogToConsole(logging::LogSeverity level, const std::string& log_event) {
35 switch (level) {
36 case logging::LOG_ERROR:
37 RAW_LOG(ERROR, log_event.c_str());
38 return;
39 case logging::LOG_WARNING:
40 RAW_LOG(WARNING, log_event.c_str());
41 return;
42 case logging::LOG_INFO:
43 RAW_LOG(INFO, log_event.c_str());
44 return;
45 }
46
47 LOG(ERROR) << "LogToConsole() missing case for LogSeverity=" << level;
48 NOTREACHED();
49 }
50
18 } // namespace 51 } // namespace
19 52
20 void Log(const char* format, ...) { 53 void ClearLog() {
54 g_logger.Pointer()->SetHistorySize(google_apis::kDefaultHistorySize);
55 }
56
57 void Log(tracked_objects::Location location,
58 logging::LogSeverity severity,
59 const char* format,
60 ...) {
61 // Ignore log if level severity is not high enough.
62 if (severity < logging::GetMinLogLevel())
63 return;
64
21 std::string what; 65 std::string what;
22 66
23 va_list args; 67 va_list args;
24 va_start(args, format); 68 va_start(args, format);
25 base::StringAppendV(&what, format, args); 69 base::StringAppendV(&what, format, args);
26 va_end(args); 70 va_end(args);
27 71
72 // Use same output format as normal console logger.
73 base::FilePath path(FILE_PATH_LITERAL(location.file_name()));
tzik 2013/05/24 04:08:32 FILE_PATH_LITERAL is only for a literal. This will
calvinlo 2013/05/24 05:12:43 Thanks for Hiroki for pointing out that I can prob
74 std::string log_output = base::StringPrintf(
75 "[%s: %s(%d)] %s",
76 LogSeverityToString(severity).c_str(),
77 path.BaseName().AsUTF8Unsafe().c_str(),
78 location.line_number(),
79 what.c_str());
80
81 // Log to WebUI.
28 // On thread-safety: LazyInstance guarantees thread-safety for the object 82 // On thread-safety: LazyInstance guarantees thread-safety for the object
29 // creation. EventLogger::Log() internally maintains the lock. 83 // creation. EventLogger::Log() internally maintains the lock.
30 google_apis::EventLogger* ptr = g_logger.Pointer(); 84 google_apis::EventLogger* ptr = g_logger.Pointer();
31 ptr->Log("%s", what.c_str()); 85 ptr->Log("%s", log_output.c_str());
86
87 // Log to console.
88 LogToConsole(severity, log_output);
tzik 2013/05/24 04:08:32 Can we use RowLog instead? And then can we drop Lo
calvinlo 2013/05/24 05:12:43 I tried this originally but I couldn't figure out
tzik 2013/05/24 11:17:38 Just like below seems to work: logging::RawLog(sev
32 } 89 }
33 90
34 std::vector<google_apis::EventLogger::Event> GetLogHistory() { 91 std::vector<google_apis::EventLogger::Event> GetLogHistory() {
35 google_apis::EventLogger* ptr = g_logger.Pointer(); 92 google_apis::EventLogger* ptr = g_logger.Pointer();
36 return ptr->GetHistory(); 93 return ptr->GetHistory();
37 } 94 }
38 95
39 } // namespace util 96 } // namespace util
40 } // namespace sync_file_system 97 } // namespace sync_file_system
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698