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..74a5bdec2587aa24596b7dd9728261c8b3db63b7 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,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"; |
| +} |
| + |
| +void LogToConsole(logging::LogSeverity level, const std::string& log_event) { |
| + switch (level) { |
| + case logging::LOG_ERROR: |
| + RAW_LOG(ERROR, log_event.c_str()); |
| + return; |
| + case logging::LOG_WARNING: |
| + RAW_LOG(WARNING, log_event.c_str()); |
| + return; |
| + case logging::LOG_INFO: |
| + RAW_LOG(INFO, log_event.c_str()); |
| + return; |
| + } |
| + |
| + LOG(ERROR) << "LogToConsole() missing case for LogSeverity=" << level; |
| + NOTREACHED(); |
| +} |
| + |
| } // namespace |
| -void Log(const char* format, ...) { |
| +void ClearLog() { |
| + g_logger.Pointer()->SetHistorySize(google_apis::kDefaultHistorySize); |
| +} |
| + |
| +void Log(tracked_objects::Location location, |
| + logging::LogSeverity severity, |
| + 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 +69,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(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
|
| + 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. |
| + 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
|
| } |
| std::vector<google_apis::EventLogger::Event> GetLogHistory() { |