Chromium Code Reviews| Index: chrome/browser/sync_file_system/logger.cc |
| diff --git a/chrome/browser/sync_file_system/logger.cc b/chrome/browser/sync_file_system/logger.cc |
| index 55705c95b16666dccbe2c553a4e7d027887471a5..07bb81fd88ca9335de6e0ec43b204b9f1312e6a1 100644 |
| --- a/chrome/browser/sync_file_system/logger.cc |
| +++ b/chrome/browser/sync_file_system/logger.cc |
| @@ -15,9 +15,51 @@ namespace { |
| static base::LazyInstance<google_apis::EventLogger> g_logger = |
| LAZY_INSTANCE_INITIALIZER; |
| +std::string LogSeverityToString(logging::LogSeverity level) { |
| + switch (level) { |
| + case logging::LOG_ERROR: |
| + return "Error"; |
| + case logging::LOG_WARNING: |
| + return "Warning"; |
| + case logging::LOG_INFO: |
| + return "Info"; |
| + } |
| + |
| + NOTREACHED(); |
| + return "Unknown Log Severity"; |
| +} |
| + |
| +// Need helper function since the LOG macro can't handle argument values. |
| +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.
|
| + switch (level) { |
| + case logging::LOG_ERROR: |
| + LOG(ERROR) << log_event; |
| + return; |
| + case logging::LOG_WARNING: |
| + LOG(WARNING) << log_event; |
| + return; |
| + case logging::LOG_INFO: |
| + LOG(INFO) << log_event; |
| + return; |
| + } |
| + |
| + LOG(FATAL) << "LogToConsole() missing case for LogSeverity=" << level; |
| + NOTREACHED(); |
| +} |
| + |
| } // namespace |
| -void Log(const char* format, ...) { |
| +// 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.
|
| +void ClearLog() { |
| + g_logger.Pointer()->SetHistorySize(google_apis::kDefaultHistorySize); |
| +} |
| + |
| +// Static |
|
nhiroki
2013/05/22 09:18:24
ditto.
calvinlo
2013/05/23 10:00:15
Done.
|
| +void Log(logging::LogSeverity level, const char* format, ...) { |
| + // Ignore log if level is not high enough. |
| + if (level < logging::GetMinLogLevel()) |
| + return; |
| + |
| std::string what; |
| va_list args; |
| @@ -28,9 +70,14 @@ void Log(const char* format, ...) { |
| // On thread-safety: LazyInstance guarantees thread-safety for the object |
| // creation. EventLogger::Log() internally maintains the lock. |
| google_apis::EventLogger* ptr = g_logger.Pointer(); |
| - ptr->Log("%s", what.c_str()); |
| + std::string level_string = "[" + LogSeverityToString(level) + "] "; |
| + 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
|
| + |
| + // Mirror log to console just in case syncfs-internals page crashes. |
| + LogToConsole(level, what); |
| } |
| +// Static |
|
nhiroki
2013/05/22 09:18:24
ditto.
calvinlo
2013/05/23 10:00:15
Done.
|
| std::vector<google_apis::EventLogger::Event> GetLogHistory() { |
| google_apis::EventLogger* ptr = g_logger.Pointer(); |
| return ptr->GetHistory(); |