Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2012 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // IMPORTANT | |
| 12 // Since this file includes Chromium source files, it must not include | |
| 13 // logging.h since logging.h defines some of the same macros as Chrome does | |
| 14 // and we'll run into conflict. | |
| 15 | |
| 16 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) | 11 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 17 #include <CoreServices/CoreServices.h> | 12 #include <CoreServices/CoreServices.h> |
| 18 #endif // OS_MACOSX | 13 #endif // OS_MACOSX |
| 19 | 14 |
| 20 #include <algorithm> | 15 #include <algorithm> |
| 21 #include <iomanip> | 16 #include <iomanip> |
| 22 | 17 |
| 23 #include "base/atomicops.h" | 18 #include "base/atomicops.h" |
| 19 #include "base/logging.h" | |
| 24 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 25 #include "base/threading/platform_thread.h" | 21 #include "base/threading/platform_thread.h" |
| 26 #include "third_party/webrtc/base/ipaddress.h" | 22 #include "third_party/webrtc/base/ipaddress.h" |
| 27 #include "third_party/webrtc/base/stream.h" | 23 #include "third_party/webrtc/base/stream.h" |
| 28 #include "third_party/webrtc/base/stringencode.h" | 24 #include "third_party/webrtc/base/stringencode.h" |
| 29 #include "third_party/webrtc/base/stringutils.h" | 25 #include "third_party/webrtc/base/stringutils.h" |
| 30 #include "third_party/webrtc/base/timeutils.h" | 26 #include "third_party/webrtc/base/timeutils.h" |
| 31 #include "third_party/webrtc/overrides/webrtc/base/diagnostic_logging.h" | 27 #include "third_party/webrtc/overrides/webrtc/base/diagnostic_logging.h" |
| 28 #include "third_party/webrtc/overrides/webrtc/base/logging.h" | |
| 32 | 29 |
| 33 // From this file we can't use VLOG since it expands into usage of the __FILE__ | 30 // From this file we can't use VLOG since it expands into usage of the __FILE__ |
| 34 // macro (for correct filtering). The actual logging call from DIAGNOSTIC_LOG in | 31 // macro (for correct filtering). The actual logging call from DIAGNOSTIC_LOG in |
| 35 // ~DiagnosticLogMessage. Note that the second parameter to the LAZY_STREAM | 32 // ~DiagnosticLogMessage. Note that the second parameter to the LAZY_STREAM |
| 36 // macro is true since the filter check has already been done for | 33 // macro is true since the filter check has already been done for |
| 37 // DIAGNOSTIC_LOG. | 34 // DIAGNOSTIC_LOG. |
| 38 #define LOG_LAZY_STREAM_DIRECT(file_name, line_number, sev) \ | 35 #define LOG_LAZY_STREAM_DIRECT(file_name, line_number, sev) \ |
| 39 RTC_LAZY_STREAM(logging::LogMessage(file_name, line_number, \ | 36 RTC_LAZY_STREAM(logging::LogMessage(file_name, line_number, \ |
| 40 sev).stream(), true) | 37 sev).stream(), true) |
| 41 | 38 |
| 42 namespace rtc { | 39 namespace rtc { |
| 43 | 40 |
| 44 void (*g_logging_delegate_function)(const std::string&) = NULL; | 41 void (*g_logging_delegate_function)(const std::string&) = NULL; |
| 45 void (*g_extra_logging_init_function)( | 42 void (*g_extra_logging_init_function)( |
| 46 void (*logging_delegate_function)(const std::string&)) = NULL; | 43 void (*logging_delegate_function)(const std::string&)) = NULL; |
| 47 #ifndef NDEBUG | 44 #ifndef NDEBUG |
| 48 static_assert(sizeof(base::subtle::Atomic32) == sizeof(base::PlatformThreadId), | 45 static_assert(sizeof(base::subtle::Atomic32) == sizeof(base::PlatformThreadId), |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 72 | 69 |
| 73 char buffer[16]; | 70 char buffer[16]; |
| 74 base::snprintf(buffer, sizeof(buffer), "0x%08x", err); | 71 base::snprintf(buffer, sizeof(buffer), "0x%08x", err); |
| 75 return buffer; | 72 return buffer; |
| 76 } | 73 } |
| 77 | 74 |
| 78 ///////////////////////////////////////////////////////////////////////////// | 75 ///////////////////////////////////////////////////////////////////////////// |
| 79 // Log helper functions | 76 // Log helper functions |
| 80 ///////////////////////////////////////////////////////////////////////////// | 77 ///////////////////////////////////////////////////////////////////////////// |
| 81 | 78 |
| 79 inline int WebRtcSevToChromeSev(LoggingSeverity sev) { | |
| 80 switch (sev) { | |
| 81 case LS_ERROR: | |
| 82 return ::logging::LOG_ERROR; | |
| 83 case LS_WARNING: | |
| 84 return ::logging::LOG_WARNING; | |
| 85 case LS_INFO: | |
| 86 return ::logging::LOG_INFO; | |
| 87 case LS_VERBOSE: | |
| 88 case LS_SENSITIVE: | |
| 89 return ::logging::LOG_VERBOSE; | |
| 90 default: | |
| 91 RTC_NOTREACHED(); | |
| 92 return ::logging::LOG_FATAL; | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 inline int WebRtcVerbosityLevel(LoggingSeverity sev) { | |
| 97 switch (sev) { | |
| 98 case LS_ERROR: | |
| 99 return -2; | |
| 100 case LS_WARNING: | |
| 101 return -1; | |
| 102 case LS_INFO: // We treat 'info' and 'verbose' as the same verbosity level. | |
| 103 case LS_VERBOSE: | |
| 104 return 1; | |
| 105 case LS_SENSITIVE: | |
| 106 return 2; | |
| 107 default: | |
| 108 RTC_NOTREACHED(); | |
| 109 return 0; | |
| 110 } | |
| 111 } | |
| 112 | |
| 82 // Generates extra information for LOG_E. | 113 // Generates extra information for LOG_E. |
| 83 static std::string GenerateExtra(LogErrorContext err_ctx, | 114 static std::string GenerateExtra(LogErrorContext err_ctx, |
| 84 int err, | 115 int err, |
| 85 const char* module) { | 116 const char* module) { |
| 86 if (err_ctx != ERRCTX_NONE) { | 117 if (err_ctx != ERRCTX_NONE) { |
| 87 std::ostringstream tmp; | 118 std::ostringstream tmp; |
| 88 tmp << ": "; | 119 tmp << ": "; |
| 89 tmp << "[0x" << std::setfill('0') << std::hex << std::setw(8) << err << "]"; | 120 tmp << "[0x" << std::setfill('0') << std::hex << std::setw(8) << err << "]"; |
| 90 switch (err_ctx) { | 121 switch (err_ctx) { |
| 91 case ERRCTX_ERRNO: | 122 case ERRCTX_ERRNO: |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 break; | 159 break; |
| 129 } | 160 } |
| 130 return tmp.str(); | 161 return tmp.str(); |
| 131 } | 162 } |
| 132 return ""; | 163 return ""; |
| 133 } | 164 } |
| 134 | 165 |
| 135 DiagnosticLogMessage::DiagnosticLogMessage(const char* file, | 166 DiagnosticLogMessage::DiagnosticLogMessage(const char* file, |
| 136 int line, | 167 int line, |
| 137 LoggingSeverity severity, | 168 LoggingSeverity severity, |
| 138 bool log_to_chrome, | |
| 139 LogErrorContext err_ctx, | 169 LogErrorContext err_ctx, |
| 140 int err) | 170 int err) |
| 141 : file_name_(file), | 171 : file_name_(file), |
| 142 line_(line), | 172 line_(line), |
| 143 severity_(severity), | 173 severity_(severity), |
| 144 log_to_chrome_(log_to_chrome) { | 174 log_to_chrome_(CheckVlogIsOnHelper(severity, file, strlen(file) + 1)) { |
| 145 extra_ = GenerateExtra(err_ctx, err, NULL); | 175 extra_ = GenerateExtra(err_ctx, err, NULL); |
| 146 } | 176 } |
| 147 | 177 |
| 148 DiagnosticLogMessage::DiagnosticLogMessage(const char* file, | 178 DiagnosticLogMessage::DiagnosticLogMessage(const char* file, |
| 149 int line, | 179 int line, |
| 150 LoggingSeverity severity, | 180 LoggingSeverity severity, |
| 151 bool log_to_chrome, | |
| 152 LogErrorContext err_ctx, | 181 LogErrorContext err_ctx, |
| 153 int err, | 182 int err, |
| 154 const char* module) | 183 const char* module) |
| 155 : file_name_(file), | 184 : file_name_(file), |
| 156 line_(line), | 185 line_(line), |
| 157 severity_(severity), | 186 severity_(severity), |
| 158 log_to_chrome_(log_to_chrome) { | 187 log_to_chrome_(CheckVlogIsOnHelper(severity, file, strlen(file) + 1)) { |
| 159 extra_ = GenerateExtra(err_ctx, err, module); | 188 extra_ = GenerateExtra(err_ctx, err, module); |
| 160 } | 189 } |
| 161 | 190 |
| 162 DiagnosticLogMessage::~DiagnosticLogMessage() { | 191 DiagnosticLogMessage::~DiagnosticLogMessage() { |
| 163 const bool call_delegate = | 192 const bool call_delegate = |
| 164 g_logging_delegate_function && severity_ <= LS_INFO; | 193 g_logging_delegate_function && severity_ <= LS_INFO; |
| 165 | 194 |
| 166 if (call_delegate || log_to_chrome_) { | 195 if (call_delegate || log_to_chrome_) { |
| 167 print_stream_ << extra_; | 196 print_stream_ << extra_; |
| 168 const std::string& str = print_stream_.str(); | 197 const std::string& str = print_stream_.str(); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 179 | 208 |
| 180 // static | 209 // static |
| 181 void LogMessage::LogToDebug(int min_sev) { | 210 void LogMessage::LogToDebug(int min_sev) { |
| 182 logging::SetMinLogLevel(min_sev); | 211 logging::SetMinLogLevel(min_sev); |
| 183 } | 212 } |
| 184 | 213 |
| 185 // Note: this function is a copy from the overriden libjingle implementation. | 214 // Note: this function is a copy from the overriden libjingle implementation. |
| 186 void LogMultiline(LoggingSeverity level, const char* label, bool input, | 215 void LogMultiline(LoggingSeverity level, const char* label, bool input, |
| 187 const void* data, size_t len, bool hex_mode, | 216 const void* data, size_t len, bool hex_mode, |
| 188 LogMultilineState* state) { | 217 LogMultilineState* state) { |
| 218 // TODO(grunell): This will not do the expected verbosity level checking. We | |
| 219 // need a macro for the multiline logging. | |
|
tommi
2015/09/15 15:06:29
is this worthy of a bug?
Henrik Grunell WebRTC
2015/09/17 07:50:17
Yes. https://code.google.com/p/webrtc/issues/detai
| |
| 189 if (!LOG_RTC_CHECK_LEVEL_V(level)) | 220 if (!LOG_RTC_CHECK_LEVEL_V(level)) |
| 190 return; | 221 return; |
| 191 | 222 |
| 192 const char * direction = (input ? " << " : " >> "); | 223 const char * direction = (input ? " << " : " >> "); |
| 193 | 224 |
| 194 // NULL data means to flush our count of unprintable characters. | 225 // NULL data means to flush our count of unprintable characters. |
| 195 if (!data) { | 226 if (!data) { |
| 196 if (state && state->unprintable_count_[input]) { | 227 if (state && state->unprintable_count_[input]) { |
| 197 LOG_V(level) << label << direction << "## " | 228 LOG_V(level) << label << direction << "## " |
| 198 << state->unprintable_count_[input] | 229 << state->unprintable_count_[input] |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 g_extra_logging_init_function(delegate); | 357 g_extra_logging_init_function(delegate); |
| 327 } | 358 } |
| 328 | 359 |
| 329 void SetExtraLoggingInit( | 360 void SetExtraLoggingInit( |
| 330 void (*function)(void (*delegate)(const std::string&))) { | 361 void (*function)(void (*delegate)(const std::string&))) { |
| 331 RTC_CHECK(function); | 362 RTC_CHECK(function); |
| 332 RTC_CHECK(!g_extra_logging_init_function); | 363 RTC_CHECK(!g_extra_logging_init_function); |
| 333 g_extra_logging_init_function = function; | 364 g_extra_logging_init_function = function; |
| 334 } | 365 } |
| 335 | 366 |
| 367 bool CheckVlogIsOnHelper( | |
| 368 rtc::LoggingSeverity severity, const char* file, size_t N) { | |
| 369 return rtc::WebRtcVerbosityLevel(severity) <= | |
| 370 ::logging::GetVlogLevelHelper(file, N); | |
| 371 } | |
| 372 | |
| 336 } // namespace rtc | 373 } // namespace rtc |
| OLD | NEW |