From 99eeee39ebc98584e401ec5057ea9fa82f09d6a8 Mon Sep 17 00:00:00 2001 From: Tommi Date: Wed, 13 May 2015 23:49:46 +0200 Subject: [PATCH] Fix logging in Chrome. The constants we were using for severities don't match Chrome's, so I added a little translation function. A longer term fix could be to simply use the same values as in Chrome to not need the translation. That will however be a bigger change. BUG=chromium:401963 TBR=magjed@webrtc.org Review URL: https://webrtc-codereview.appspot.com/50949004 Cr-Commit-Position: refs/heads/master@{#9188} --- .../overrides/webrtc/base/diagnostic_logging.h | 17 +++++++++++++++++ webrtc/overrides/webrtc/base/logging.cc | 7 +++++-- webrtc/overrides/webrtc/base/logging.h | 8 +++++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/webrtc/overrides/webrtc/base/diagnostic_logging.h b/webrtc/overrides/webrtc/base/diagnostic_logging.h index 403bfc90be..4cd80c83ff 100644 --- a/webrtc/overrides/webrtc/base/diagnostic_logging.h +++ b/webrtc/overrides/webrtc/base/diagnostic_logging.h @@ -70,6 +70,23 @@ enum LoggingSeverity { LS_ERROR = 1, WARNING = LS_WARNING, LERROR = LS_ERROR }; +inline int WebRtcSevToChromeSev(LoggingSeverity sev) { + switch (sev) { + case LS_ERROR: + return ::logging::LOG_ERROR; + case LS_WARNING: + return ::logging::LOG_WARNING; + case LS_INFO: + return ::logging::LOG_INFO; + case LS_VERBOSE: + case LS_SENSITIVE: + return ::logging::LOG_VERBOSE; + default: + NOTREACHED(); + return ::logging::LOG_FATAL; + } +} + // LogErrorContext assists in interpreting the meaning of an error value. enum LogErrorContext { ERRCTX_NONE, diff --git a/webrtc/overrides/webrtc/base/logging.cc b/webrtc/overrides/webrtc/base/logging.cc index 20b3ba380f..fa86570b3f 100644 --- a/webrtc/overrides/webrtc/base/logging.cc +++ b/webrtc/overrides/webrtc/base/logging.cc @@ -166,8 +166,11 @@ DiagnosticLogMessage::~DiagnosticLogMessage() { if (call_delegate || log_to_chrome_) { print_stream_ << extra_; const std::string& str = print_stream_.str(); - if (log_to_chrome_) - LOG_LAZY_STREAM_DIRECT(file_name_, line_, severity_) << str; + if (log_to_chrome_) { + LOG_LAZY_STREAM_DIRECT(file_name_, line_, + rtc::WebRtcSevToChromeSev(severity_)) << str; + } + if (g_logging_delegate_function && severity_ <= LS_INFO) { g_logging_delegate_function(str); } diff --git a/webrtc/overrides/webrtc/base/logging.h b/webrtc/overrides/webrtc/base/logging.h index 78f48f4359..8df2d19f46 100644 --- a/webrtc/overrides/webrtc/base/logging.h +++ b/webrtc/overrides/webrtc/base/logging.h @@ -38,13 +38,15 @@ #if defined(LOGGING_INSIDE_WEBRTC) +#define WEBRTC_VLOG_IS_ON(sev) VLOG_IS_ON(rtc::WebRtcSevToChromeSev(sev)) + #define DIAGNOSTIC_LOG(sev, ctx, err, ...) \ rtc::DiagnosticLogMessage( \ - __FILE__, __LINE__, sev, VLOG_IS_ON(sev), \ + __FILE__, __LINE__, sev, WEBRTC_VLOG_IS_ON(sev), \ rtc::ERRCTX_ ## ctx, err, ##__VA_ARGS__).stream() -#define LOG_CHECK_LEVEL(sev) VLOG_IS_ON(rtc::sev) -#define LOG_CHECK_LEVEL_V(sev) VLOG_IS_ON(sev) +#define LOG_CHECK_LEVEL(sev) WEBRTC_VLOG_IS_ON(rtc::sev) +#define LOG_CHECK_LEVEL_V(sev) WEBRTC_VLOG_IS_ON(sev) #define LOG_V(sev) DIAGNOSTIC_LOG(sev, NONE, 0) #undef LOG