diff --git a/webrtc/base/checks.h b/webrtc/base/checks.h index ad0954d410..98e896a15b 100644 --- a/webrtc/base/checks.h +++ b/webrtc/base/checks.h @@ -14,13 +14,6 @@ #include #include -#ifdef WEBRTC_CHROMIUM_BUILD -// Include logging.h in a Chromium build to enable the overrides mechanism for -// using Chromium's macros. Otherwise, don't depend on logging.h. -// TODO(ajm): Ideally, checks.h would be combined with logging.h, but -// consolidation with system_wrappers/logging.h should happen first. -#include "webrtc/base/logging.h" -#endif #include "webrtc/typedefs.h" // The macros here print a message to stderr and abort under various @@ -59,6 +52,9 @@ // RTC_DCHECK. // // - FATAL() aborts unconditionally. +// +// TODO(ajm): Ideally, checks.h would be combined with logging.h, but +// consolidation with system_wrappers/logging.h should happen first. namespace rtc { diff --git a/webrtc/overrides/webrtc/base/diagnostic_logging.h b/webrtc/overrides/webrtc/base/diagnostic_logging.h index a544ee5f7c..d0cae4b47e 100644 --- a/webrtc/overrides/webrtc/base/diagnostic_logging.h +++ b/webrtc/overrides/webrtc/base/diagnostic_logging.h @@ -14,7 +14,7 @@ #include #include -#include "base/logging.h" +#include "third_party/webrtc/base/checks.h" #include "third_party/webrtc/base/scoped_ref_ptr.h" namespace rtc { @@ -72,40 +72,6 @@ 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; - } -} - -inline int WebRtcVerbosityLevel(LoggingSeverity sev) { - switch (sev) { - case LS_ERROR: - return -2; - case LS_WARNING: - return -1; - case LS_INFO: // We treat 'info' and 'verbose' as the same verbosity level. - case LS_VERBOSE: - return 1; - case LS_SENSITIVE: - return 2; - default: - NOTREACHED(); - return 0; - } -} - // LogErrorContext assists in interpreting the meaning of an error value. enum LogErrorContext { ERRCTX_NONE, @@ -124,10 +90,9 @@ enum LogErrorContext { class DiagnosticLogMessage { public: DiagnosticLogMessage(const char* file, int line, LoggingSeverity severity, - bool log_to_chrome, LogErrorContext err_ctx, int err); + LogErrorContext err_ctx, int err); DiagnosticLogMessage(const char* file, int line, LoggingSeverity severity, - bool log_to_chrome, LogErrorContext err_ctx, int err, - const char* module); + LogErrorContext err_ctx, int err, const char* module); ~DiagnosticLogMessage(); void CreateTimestamp(); diff --git a/webrtc/overrides/webrtc/base/logging.cc b/webrtc/overrides/webrtc/base/logging.cc index 58a834de3f..27254e3421 100644 --- a/webrtc/overrides/webrtc/base/logging.cc +++ b/webrtc/overrides/webrtc/base/logging.cc @@ -9,9 +9,9 @@ */ // IMPORTANT -// Since this file includes Chromium source files, it must not include -// logging.h since logging.h defines some of the same macros as Chrome does -// and we'll run into conflict. +// Since this file includes Chromium headers, it must not include +// third_party/webrtc/base/logging.h since it defines some of the same macros as +// Chromium does and we'll run into conflicts. #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) #include @@ -21,6 +21,7 @@ #include #include "base/atomicops.h" +#include "base/logging.h" #include "base/strings/string_util.h" #include "base/threading/platform_thread.h" #include "third_party/webrtc/base/ipaddress.h" @@ -79,6 +80,40 @@ std::string ErrorName(int err, const ConstantLabel* err_table) { // Log helper functions ///////////////////////////////////////////////////////////////////////////// +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; + } +} + +inline int WebRtcVerbosityLevel(LoggingSeverity sev) { + switch (sev) { + case LS_ERROR: + return -2; + case LS_WARNING: + return -1; + case LS_INFO: // We treat 'info' and 'verbose' as the same verbosity level. + case LS_VERBOSE: + return 1; + case LS_SENSITIVE: + return 2; + default: + NOTREACHED(); + return 0; + } +} + // Generates extra information for LOG_E. static std::string GenerateExtra(LogErrorContext err_ctx, int err, @@ -135,27 +170,25 @@ static std::string GenerateExtra(LogErrorContext err_ctx, DiagnosticLogMessage::DiagnosticLogMessage(const char* file, int line, LoggingSeverity severity, - bool log_to_chrome, LogErrorContext err_ctx, int err) : file_name_(file), line_(line), severity_(severity), - log_to_chrome_(log_to_chrome) { + log_to_chrome_(CheckVlogIsOnHelper(severity, file, strlen(file) + 1)) { extra_ = GenerateExtra(err_ctx, err, NULL); } DiagnosticLogMessage::DiagnosticLogMessage(const char* file, int line, LoggingSeverity severity, - bool log_to_chrome, LogErrorContext err_ctx, int err, const char* module) : file_name_(file), line_(line), severity_(severity), - log_to_chrome_(log_to_chrome) { + log_to_chrome_(CheckVlogIsOnHelper(severity, file, strlen(file) + 1)) { extra_ = GenerateExtra(err_ctx, err, module); } @@ -186,6 +219,9 @@ void LogMessage::LogToDebug(int min_sev) { void LogMultiline(LoggingSeverity level, const char* label, bool input, const void* data, size_t len, bool hex_mode, LogMultilineState* state) { + // TODO(grunell): This will not do the expected verbosity level checking. We + // need a macro for the multiline logging. + // https://code.google.com/p/webrtc/issues/detail?id=5011 if (!LOG_CHECK_LEVEL_V(level)) return; @@ -333,4 +369,10 @@ void SetExtraLoggingInit( g_extra_logging_init_function = function; } +bool CheckVlogIsOnHelper( + rtc::LoggingSeverity severity, const char* file, size_t N) { + return rtc::WebRtcVerbosityLevel(severity) <= + ::logging::GetVlogLevelHelper(file, N); +} + } // namespace rtc diff --git a/webrtc/overrides/webrtc/base/logging.h b/webrtc/overrides/webrtc/base/logging.h index ef471ee5e5..43de221e18 100644 --- a/webrtc/overrides/webrtc/base/logging.h +++ b/webrtc/overrides/webrtc/base/logging.h @@ -38,15 +38,25 @@ #if defined(LOGGING_INSIDE_WEBRTC) -#define WEBRTC_VLOG_IS_ON(sev) VLOG_IS_ON(rtc::WebRtcVerbosityLevel(sev)) +namespace rtc { + +// Note that |N| is the size *with* the null terminator. +bool CheckVlogIsOnHelper(LoggingSeverity severity, + const char* file, size_t N); + +template +bool CheckVlogIsOn(LoggingSeverity severity, const char (&file)[N]) { + return CheckVlogIsOnHelper(severity, file, N); +} + +} // namespace rtc #define DIAGNOSTIC_LOG(sev, ctx, err, ...) \ rtc::DiagnosticLogMessage( \ - __FILE__, __LINE__, sev, WEBRTC_VLOG_IS_ON(sev), \ - rtc::ERRCTX_ ## ctx, err, ##__VA_ARGS__).stream() + __FILE__, __LINE__, sev, rtc::ERRCTX_ ## ctx, err, ##__VA_ARGS__).stream() -#define LOG_CHECK_LEVEL(sev) WEBRTC_VLOG_IS_ON(rtc::sev) -#define LOG_CHECK_LEVEL_V(sev) WEBRTC_VLOG_IS_ON(sev) +#define LOG_CHECK_LEVEL(sev) CheckVlogIsOn(rtc::sev, __FILE__) +#define LOG_CHECK_LEVEL_V(sev) CheckVlogIsOn(sev, __FILE__) #define LOG_V(sev) DIAGNOSTIC_LOG(sev, NONE, 0) #undef LOG