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..43b18c6b156f0e193a5e0e4b04b9fd39e5c062ae 100644 |
--- a/chrome/browser/sync_file_system/logger.cc |
+++ b/chrome/browser/sync_file_system/logger.cc |
@@ -4,7 +4,9 @@ |
#include "chrome/browser/sync_file_system/logger.h" |
+#include "base/file_util.h" |
#include "base/lazy_instance.h" |
+#include "base/location.h" |
#include "base/stringprintf.h" |
#include "chrome/browser/google_apis/event_logger.h" |
@@ -15,9 +17,34 @@ 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"; |
+} |
+ |
} // namespace |
-void Log(const char* format, ...) { |
+void ClearLog() { |
+ g_logger.Pointer()->SetHistorySize(google_apis::kDefaultHistorySize); |
+} |
+ |
+void Log(logging::LogSeverity severity, |
+ const tracked_objects::Location& location, |
+ const char* format, |
+ ...) { |
+ // Ignore log if level severity is not high enough. |
+ if (severity < logging::GetMinLogLevel()) |
+ return; |
+ |
std::string what; |
va_list args; |
@@ -25,10 +52,23 @@ void Log(const char* format, ...) { |
base::StringAppendV(&what, format, args); |
va_end(args); |
+ // Use same output format as normal console logger. |
+ base::FilePath path = base::FilePath::FromUTF8Unsafe(location.file_name()); |
+ std::string log_output = base::StringPrintf( |
+ "[%s: %s(%d)] %s", |
+ LogSeverityToString(severity).c_str(), |
+ path.BaseName().AsUTF8Unsafe().c_str(), |
+ location.line_number(), |
+ what.c_str()); |
+ |
+ // Log to WebUI. |
// 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()); |
+ ptr->Log("%s", log_output.c_str()); |
+ |
+ // Log to console. |
+ logging::RawLog(severity, log_output.c_str()); |
} |
std::vector<google_apis::EventLogger::Event> GetLogHistory() { |