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..64c89bbe0cf51aa4be025f77307ed66de869791c 100644 |
--- a/chrome/browser/sync_file_system/logger.cc |
+++ b/chrome/browser/sync_file_system/logger.cc |
@@ -17,7 +17,48 @@ static base::LazyInstance<google_apis::EventLogger> g_logger = |
} // namespace |
-void Log(const char* format, ...) { |
+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) { |
+ 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(); |
+} |
+ |
+void Log(logging::LogSeverity level, std::string& format, ...) { |
+ va_list args; |
+ Log(level, format.c_str(), args); |
+} |
+ |
+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,7 +69,11 @@ 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()); |
+ |
+ // Mirror log to console just in case syncfs-internals page crashes. |
+ LogToConsole(level, what); |
} |
std::vector<google_apis::EventLogger::Event> GetLogHistory() { |