| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "remoting/base/logger.h" | |
| 6 | |
| 7 #include <stdarg.h> // va_list | |
| 8 | |
| 9 #include "base/logging.h" | |
| 10 #include "base/message_loop.h" | |
| 11 #include "base/stringprintf.h" | |
| 12 | |
| 13 namespace remoting { | |
| 14 | |
| 15 // Copied from base/logging.cc. | |
| 16 const char* const Logger::log_severity_names[logging::LOG_NUM_SEVERITIES] = { | |
| 17 "INFO", "WARNING", "ERROR", "ERROR_REPORT", "FATAL" | |
| 18 }; | |
| 19 | |
| 20 Logger::Logger() | |
| 21 : message_loop_(NULL) { | |
| 22 } | |
| 23 | |
| 24 Logger::~Logger() { | |
| 25 } | |
| 26 | |
| 27 void Logger::Log(logging::LogSeverity severity, const char* format, ...) { | |
| 28 va_list ap; | |
| 29 va_start(ap, format); | |
| 30 va_Log(severity, format, ap); | |
| 31 va_end(ap); | |
| 32 } | |
| 33 | |
| 34 void Logger::VLog(int verboselevel, const char* format, ...) { | |
| 35 va_list ap; | |
| 36 va_start(ap, format); | |
| 37 va_VLog(verboselevel, format, ap); | |
| 38 va_end(ap); | |
| 39 } | |
| 40 | |
| 41 void Logger::va_Log(logging::LogSeverity severity, | |
| 42 const char* format, va_list ap) { | |
| 43 DCHECK(severity >= 0 && severity <= logging::LOG_NUM_SEVERITIES); | |
| 44 | |
| 45 // Based in LOG_IS_ON macro in base/logging.h. | |
| 46 if (severity >= ::logging::GetMinLogLevel()) { | |
| 47 std::string message; | |
| 48 base::StringAppendV(&message, format, ap); | |
| 49 | |
| 50 // Standard logging. | |
| 51 logging::LogMessage(__FILE__, __LINE__, severity).stream() << message; | |
| 52 | |
| 53 // Send log message to the host UI. | |
| 54 LogToUI_CorrectThread(StringPrintf("LOG(%s) %s", | |
| 55 log_severity_names[severity], | |
| 56 message.c_str())); | |
| 57 } | |
| 58 | |
| 59 va_end(ap); | |
| 60 } | |
| 61 | |
| 62 void Logger::va_VLog(int verboselevel, | |
| 63 const char* format, | |
| 64 va_list ap) { | |
| 65 if (VLOG_IS_ON(verboselevel)) { | |
| 66 std::string message; | |
| 67 base::StringAppendV(&message, format, ap); | |
| 68 | |
| 69 // Standard verbose logging. | |
| 70 VLOG(verboselevel) << message; | |
| 71 | |
| 72 // Send log message to the host UI. | |
| 73 LogToUI_CorrectThread(StringPrintf("VLOG(%d) %s", | |
| 74 verboselevel, message.c_str())); | |
| 75 } | |
| 76 } | |
| 77 | |
| 78 void Logger::LogToUI_CorrectThread(const std::string& message) { | |
| 79 if (!message_loop_) | |
| 80 return; | |
| 81 | |
| 82 if (message_loop_ != MessageLoop::current()) { | |
| 83 message_loop_->PostTask( | |
| 84 FROM_HERE, | |
| 85 NewRunnableMethod(this, &Logger::LogToUI_CorrectThread, message)); | |
| 86 return; | |
| 87 } | |
| 88 | |
| 89 LogToUI(message); | |
| 90 } | |
| 91 | |
| 92 void Logger::LogToUI(const std::string& message) { | |
| 93 } | |
| 94 | |
| 95 } // namespace remoting | |
| OLD | NEW |