Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 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 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 // of destructors at program exit. Let the person who sets the stream trigger | 107 // of destructors at program exit. Let the person who sets the stream trigger |
| 108 // cleanup by setting to NULL, or let it leak (safe at program exit). | 108 // cleanup by setting to NULL, or let it leak (safe at program exit). |
| 109 LogMessage::StreamList LogMessage::streams_ GUARDED_BY(LogMessage::crit_); | 109 LogMessage::StreamList LogMessage::streams_ GUARDED_BY(LogMessage::crit_); |
| 110 | 110 |
| 111 // Boolean options default to false (0) | 111 // Boolean options default to false (0) |
| 112 bool LogMessage::thread_, LogMessage::timestamp_; | 112 bool LogMessage::thread_, LogMessage::timestamp_; |
| 113 | 113 |
| 114 LogMessage::LogMessage(const char* file, int line, LoggingSeverity sev, | 114 LogMessage::LogMessage(const char* file, int line, LoggingSeverity sev, |
| 115 LogErrorContext err_ctx, int err, const char* module) | 115 LogErrorContext err_ctx, int err, const char* module) |
| 116 : severity_(sev), | 116 : severity_(sev), |
| 117 android_tag_(kLibjingle), | |
|
AlexG
2015/09/14 20:12:33
kLibjingle is defined for WEBRTC_ANDROID only - th
jiayl2
2015/09/14 20:54:38
Done.
| |
| 117 warn_slow_logs_delay_(WARN_SLOW_LOGS_DELAY) { | 118 warn_slow_logs_delay_(WARN_SLOW_LOGS_DELAY) { |
| 118 if (timestamp_) { | 119 if (timestamp_) { |
| 119 uint32 time = TimeSince(LogStartTime()); | 120 uint32 time = TimeSince(LogStartTime()); |
| 120 // Also ensure WallClockStartTime is initialized, so that it matches | 121 // Also ensure WallClockStartTime is initialized, so that it matches |
| 121 // LogStartTime. | 122 // LogStartTime. |
| 122 WallClockStartTime(); | 123 WallClockStartTime(); |
| 123 print_stream_ << "[" << std::setfill('0') << std::setw(3) << (time / 1000) | 124 print_stream_ << "[" << std::setfill('0') << std::setw(3) << (time / 1000) |
| 124 << ":" << std::setw(3) << (time % 1000) << std::setfill(' ') | 125 << ":" << std::setw(3) << (time % 1000) << std::setfill(' ') |
| 125 << "] "; | 126 << "] "; |
| 126 } | 127 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 168 break; | 169 break; |
| 169 } | 170 } |
| 170 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) | 171 #endif // WEBRTC_MAC && !defined(WEBRTC_IOS) |
| 171 default: | 172 default: |
| 172 break; | 173 break; |
| 173 } | 174 } |
| 174 extra_ = tmp.str(); | 175 extra_ = tmp.str(); |
| 175 } | 176 } |
| 176 } | 177 } |
| 177 | 178 |
| 179 LogMessage::LogMessage(const char* file, | |
| 180 int line, | |
| 181 LoggingSeverity sev, | |
| 182 const std::string& tag) | |
| 183 : LogMessage(file, line, sev, ERRCTX_NONE, 0 /* err */, NULL /* module */) { | |
| 184 android_tag_ = tag; | |
|
AlexG
2015/09/14 20:12:33
Move this to ctor initialization list?
jiayl2
2015/09/14 20:54:38
That will cause compile error
| |
| 185 } | |
| 186 | |
| 178 LogMessage::~LogMessage() { | 187 LogMessage::~LogMessage() { |
| 179 if (!extra_.empty()) | 188 if (!extra_.empty()) |
| 180 print_stream_ << " : " << extra_; | 189 print_stream_ << " : " << extra_; |
| 181 print_stream_ << std::endl; | 190 print_stream_ << std::endl; |
| 182 | 191 |
| 183 const std::string& str = print_stream_.str(); | 192 const std::string& str = print_stream_.str(); |
| 184 if (severity_ >= dbg_sev_) { | 193 if (severity_ >= dbg_sev_) { |
| 185 OutputToDebug(str, severity_); | 194 OutputToDebug(str, severity_, android_tag_); |
| 186 } | 195 } |
| 187 | 196 |
| 188 uint32 before = Time(); | 197 uint32 before = Time(); |
| 189 // Must lock streams_ before accessing | 198 // Must lock streams_ before accessing |
| 190 CritScope cs(&crit_); | 199 CritScope cs(&crit_); |
| 191 for (StreamList::iterator it = streams_.begin(); it != streams_.end(); ++it) { | 200 for (StreamList::iterator it = streams_.begin(); it != streams_.end(); ++it) { |
| 192 if (severity_ >= it->second) { | 201 if (severity_ >= it->second) { |
| 193 it->first->OnLogMessage(str); | 202 it->first->OnLogMessage(str); |
| 194 } | 203 } |
| 195 } | 204 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 326 | 335 |
| 327 void LogMessage::UpdateMinLogSeverity() EXCLUSIVE_LOCKS_REQUIRED(crit_) { | 336 void LogMessage::UpdateMinLogSeverity() EXCLUSIVE_LOCKS_REQUIRED(crit_) { |
| 328 LoggingSeverity min_sev = dbg_sev_; | 337 LoggingSeverity min_sev = dbg_sev_; |
| 329 for (StreamList::iterator it = streams_.begin(); it != streams_.end(); ++it) { | 338 for (StreamList::iterator it = streams_.begin(); it != streams_.end(); ++it) { |
| 330 min_sev = std::min(dbg_sev_, it->second); | 339 min_sev = std::min(dbg_sev_, it->second); |
| 331 } | 340 } |
| 332 min_sev_ = min_sev; | 341 min_sev_ = min_sev; |
| 333 } | 342 } |
| 334 | 343 |
| 335 void LogMessage::OutputToDebug(const std::string& str, | 344 void LogMessage::OutputToDebug(const std::string& str, |
| 336 LoggingSeverity severity) { | 345 LoggingSeverity severity, |
| 346 const std::string& tag) { | |
| 337 bool log_to_stderr = log_to_stderr_; | 347 bool log_to_stderr = log_to_stderr_; |
| 338 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && (!defined(DEBUG) || defined(N DEBUG)) | 348 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && (!defined(DEBUG) || defined(N DEBUG)) |
| 339 // On the Mac, all stderr output goes to the Console log and causes clutter. | 349 // On the Mac, all stderr output goes to the Console log and causes clutter. |
| 340 // So in opt builds, don't log to stderr unless the user specifically sets | 350 // So in opt builds, don't log to stderr unless the user specifically sets |
| 341 // a preference to do so. | 351 // a preference to do so. |
| 342 CFStringRef key = CFStringCreateWithCString(kCFAllocatorDefault, | 352 CFStringRef key = CFStringCreateWithCString(kCFAllocatorDefault, |
| 343 "logToStdErr", | 353 "logToStdErr", |
| 344 kCFStringEncodingUTF8); | 354 kCFStringEncodingUTF8); |
| 345 CFStringRef domain = CFBundleGetIdentifier(CFBundleGetMainBundle()); | 355 CFStringRef domain = CFBundleGetIdentifier(CFBundleGetMainBundle()); |
| 346 if (key != NULL && domain != NULL) { | 356 if (key != NULL && domain != NULL) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 370 } | 380 } |
| 371 #endif // WEBRTC_WIN | 381 #endif // WEBRTC_WIN |
| 372 #if defined(WEBRTC_ANDROID) | 382 #if defined(WEBRTC_ANDROID) |
| 373 // Android's logging facility uses severity to log messages but we | 383 // Android's logging facility uses severity to log messages but we |
| 374 // need to map libjingle's severity levels to Android ones first. | 384 // need to map libjingle's severity levels to Android ones first. |
| 375 // Also write to stderr which maybe available to executable started | 385 // Also write to stderr which maybe available to executable started |
| 376 // from the shell. | 386 // from the shell. |
| 377 int prio; | 387 int prio; |
| 378 switch (severity) { | 388 switch (severity) { |
| 379 case LS_SENSITIVE: | 389 case LS_SENSITIVE: |
| 380 __android_log_write(ANDROID_LOG_INFO, kLibjingle, "SENSITIVE"); | 390 __android_log_write(ANDROID_LOG_INFO, tag.c_str(), "SENSITIVE"); |
| 381 if (log_to_stderr) { | 391 if (log_to_stderr) { |
| 382 fprintf(stderr, "SENSITIVE"); | 392 fprintf(stderr, "SENSITIVE"); |
| 383 fflush(stderr); | 393 fflush(stderr); |
| 384 } | 394 } |
| 385 return; | 395 return; |
| 386 case LS_VERBOSE: | 396 case LS_VERBOSE: |
| 387 prio = ANDROID_LOG_VERBOSE; | 397 prio = ANDROID_LOG_VERBOSE; |
| 388 break; | 398 break; |
| 389 case LS_INFO: | 399 case LS_INFO: |
| 390 prio = ANDROID_LOG_INFO; | 400 prio = ANDROID_LOG_INFO; |
|
AlexG
2015/09/14 20:12:33
May be use ANDROID_LOG_DEBUG here? We are mostly u
jiayl2
2015/09/14 20:54:38
Mapping info to info is more intuitive. Unless you
AlexG
2015/09/14 21:02:11
I meant all Lod.d call from Java will now actually
| |
| 391 break; | 401 break; |
| 392 case LS_WARNING: | 402 case LS_WARNING: |
| 393 prio = ANDROID_LOG_WARN; | 403 prio = ANDROID_LOG_WARN; |
| 394 break; | 404 break; |
| 395 case LS_ERROR: | 405 case LS_ERROR: |
| 396 prio = ANDROID_LOG_ERROR; | 406 prio = ANDROID_LOG_ERROR; |
| 397 break; | 407 break; |
| 398 default: | 408 default: |
| 399 prio = ANDROID_LOG_UNKNOWN; | 409 prio = ANDROID_LOG_UNKNOWN; |
| 400 } | 410 } |
| 401 | 411 |
| 402 int size = str.size(); | 412 int size = str.size(); |
| 403 int line = 0; | 413 int line = 0; |
| 404 int idx = 0; | 414 int idx = 0; |
| 405 const int max_lines = size / kMaxLogLineSize + 1; | 415 const int max_lines = size / kMaxLogLineSize + 1; |
| 406 if (max_lines == 1) { | 416 if (max_lines == 1) { |
| 407 __android_log_print(prio, kLibjingle, "%.*s", size, str.c_str()); | 417 __android_log_print(prio, tag.c_str(), "%.*s", size, str.c_str()); |
| 408 } else { | 418 } else { |
| 409 while (size > 0) { | 419 while (size > 0) { |
| 410 const int len = std::min(size, kMaxLogLineSize); | 420 const int len = std::min(size, kMaxLogLineSize); |
| 411 // Use the size of the string in the format (str may have \0 in the | 421 // Use the size of the string in the format (str may have \0 in the |
| 412 // middle). | 422 // middle). |
| 413 __android_log_print(prio, kLibjingle, "[%d/%d] %.*s", | 423 __android_log_print(prio, tag.c_str(), "[%d/%d] %.*s", |
| 414 line + 1, max_lines, | 424 line + 1, max_lines, |
| 415 len, str.c_str() + idx); | 425 len, str.c_str() + idx); |
| 416 idx += len; | 426 idx += len; |
| 417 size -= len; | 427 size -= len; |
| 418 ++line; | 428 ++line; |
| 419 } | 429 } |
| 420 } | 430 } |
| 421 #endif // WEBRTC_ANDROID | 431 #endif // WEBRTC_ANDROID |
| 422 if (log_to_stderr) { | 432 if (log_to_stderr) { |
| 423 fprintf(stderr, "%s", str.c_str()); | 433 fprintf(stderr, "%s", str.c_str()); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 542 } | 552 } |
| 543 | 553 |
| 544 if (state) { | 554 if (state) { |
| 545 state->unprintable_count_[input] = consecutive_unprintable; | 555 state->unprintable_count_[input] = consecutive_unprintable; |
| 546 } | 556 } |
| 547 } | 557 } |
| 548 | 558 |
| 549 ////////////////////////////////////////////////////////////////////// | 559 ////////////////////////////////////////////////////////////////////// |
| 550 | 560 |
| 551 } // namespace rtc | 561 } // namespace rtc |
| OLD | NEW |