Remove dependency on Chromium's base/logging.h in diagnostic_logging.h.
Depends on https://codereview.webrtc.org/1335923002/ BUG=chromium:468375 Review URL: https://codereview.webrtc.org/1338763002 Cr-Commit-Position: refs/heads/master@{#9965}
This commit is contained in:
@ -14,13 +14,6 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#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"
|
#include "webrtc/typedefs.h"
|
||||||
|
|
||||||
// The macros here print a message to stderr and abort under various
|
// The macros here print a message to stderr and abort under various
|
||||||
@ -59,6 +52,9 @@
|
|||||||
// RTC_DCHECK.
|
// RTC_DCHECK.
|
||||||
//
|
//
|
||||||
// - FATAL() aborts unconditionally.
|
// - 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 {
|
namespace rtc {
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "base/logging.h"
|
#include "third_party/webrtc/base/checks.h"
|
||||||
#include "third_party/webrtc/base/scoped_ref_ptr.h"
|
#include "third_party/webrtc/base/scoped_ref_ptr.h"
|
||||||
|
|
||||||
namespace rtc {
|
namespace rtc {
|
||||||
@ -72,40 +72,6 @@ enum LoggingSeverity { LS_ERROR = 1,
|
|||||||
WARNING = LS_WARNING,
|
WARNING = LS_WARNING,
|
||||||
LERROR = LS_ERROR };
|
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.
|
// LogErrorContext assists in interpreting the meaning of an error value.
|
||||||
enum LogErrorContext {
|
enum LogErrorContext {
|
||||||
ERRCTX_NONE,
|
ERRCTX_NONE,
|
||||||
@ -124,10 +90,9 @@ enum LogErrorContext {
|
|||||||
class DiagnosticLogMessage {
|
class DiagnosticLogMessage {
|
||||||
public:
|
public:
|
||||||
DiagnosticLogMessage(const char* file, int line, LoggingSeverity severity,
|
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,
|
DiagnosticLogMessage(const char* file, int line, LoggingSeverity severity,
|
||||||
bool log_to_chrome, LogErrorContext err_ctx, int err,
|
LogErrorContext err_ctx, int err, const char* module);
|
||||||
const char* module);
|
|
||||||
~DiagnosticLogMessage();
|
~DiagnosticLogMessage();
|
||||||
|
|
||||||
void CreateTimestamp();
|
void CreateTimestamp();
|
||||||
|
@ -9,9 +9,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
// IMPORTANT
|
// IMPORTANT
|
||||||
// Since this file includes Chromium source files, it must not include
|
// Since this file includes Chromium headers, it must not include
|
||||||
// logging.h since logging.h defines some of the same macros as Chrome does
|
// third_party/webrtc/base/logging.h since it defines some of the same macros as
|
||||||
// and we'll run into conflict.
|
// Chromium does and we'll run into conflicts.
|
||||||
|
|
||||||
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
|
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
|
||||||
#include <CoreServices/CoreServices.h>
|
#include <CoreServices/CoreServices.h>
|
||||||
@ -21,6 +21,7 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#include "base/atomicops.h"
|
#include "base/atomicops.h"
|
||||||
|
#include "base/logging.h"
|
||||||
#include "base/strings/string_util.h"
|
#include "base/strings/string_util.h"
|
||||||
#include "base/threading/platform_thread.h"
|
#include "base/threading/platform_thread.h"
|
||||||
#include "third_party/webrtc/base/ipaddress.h"
|
#include "third_party/webrtc/base/ipaddress.h"
|
||||||
@ -79,6 +80,40 @@ std::string ErrorName(int err, const ConstantLabel* err_table) {
|
|||||||
// Log helper functions
|
// 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.
|
// Generates extra information for LOG_E.
|
||||||
static std::string GenerateExtra(LogErrorContext err_ctx,
|
static std::string GenerateExtra(LogErrorContext err_ctx,
|
||||||
int err,
|
int err,
|
||||||
@ -135,27 +170,25 @@ static std::string GenerateExtra(LogErrorContext err_ctx,
|
|||||||
DiagnosticLogMessage::DiagnosticLogMessage(const char* file,
|
DiagnosticLogMessage::DiagnosticLogMessage(const char* file,
|
||||||
int line,
|
int line,
|
||||||
LoggingSeverity severity,
|
LoggingSeverity severity,
|
||||||
bool log_to_chrome,
|
|
||||||
LogErrorContext err_ctx,
|
LogErrorContext err_ctx,
|
||||||
int err)
|
int err)
|
||||||
: file_name_(file),
|
: file_name_(file),
|
||||||
line_(line),
|
line_(line),
|
||||||
severity_(severity),
|
severity_(severity),
|
||||||
log_to_chrome_(log_to_chrome) {
|
log_to_chrome_(CheckVlogIsOnHelper(severity, file, strlen(file) + 1)) {
|
||||||
extra_ = GenerateExtra(err_ctx, err, NULL);
|
extra_ = GenerateExtra(err_ctx, err, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
DiagnosticLogMessage::DiagnosticLogMessage(const char* file,
|
DiagnosticLogMessage::DiagnosticLogMessage(const char* file,
|
||||||
int line,
|
int line,
|
||||||
LoggingSeverity severity,
|
LoggingSeverity severity,
|
||||||
bool log_to_chrome,
|
|
||||||
LogErrorContext err_ctx,
|
LogErrorContext err_ctx,
|
||||||
int err,
|
int err,
|
||||||
const char* module)
|
const char* module)
|
||||||
: file_name_(file),
|
: file_name_(file),
|
||||||
line_(line),
|
line_(line),
|
||||||
severity_(severity),
|
severity_(severity),
|
||||||
log_to_chrome_(log_to_chrome) {
|
log_to_chrome_(CheckVlogIsOnHelper(severity, file, strlen(file) + 1)) {
|
||||||
extra_ = GenerateExtra(err_ctx, err, module);
|
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,
|
void LogMultiline(LoggingSeverity level, const char* label, bool input,
|
||||||
const void* data, size_t len, bool hex_mode,
|
const void* data, size_t len, bool hex_mode,
|
||||||
LogMultilineState* state) {
|
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))
|
if (!LOG_CHECK_LEVEL_V(level))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@ -333,4 +369,10 @@ void SetExtraLoggingInit(
|
|||||||
g_extra_logging_init_function = function;
|
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
|
} // namespace rtc
|
||||||
|
@ -38,15 +38,25 @@
|
|||||||
|
|
||||||
#if defined(LOGGING_INSIDE_WEBRTC)
|
#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 <size_t N>
|
||||||
|
bool CheckVlogIsOn(LoggingSeverity severity, const char (&file)[N]) {
|
||||||
|
return CheckVlogIsOnHelper(severity, file, N);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace rtc
|
||||||
|
|
||||||
#define DIAGNOSTIC_LOG(sev, ctx, err, ...) \
|
#define DIAGNOSTIC_LOG(sev, ctx, err, ...) \
|
||||||
rtc::DiagnosticLogMessage( \
|
rtc::DiagnosticLogMessage( \
|
||||||
__FILE__, __LINE__, sev, WEBRTC_VLOG_IS_ON(sev), \
|
__FILE__, __LINE__, sev, rtc::ERRCTX_ ## ctx, err, ##__VA_ARGS__).stream()
|
||||||
rtc::ERRCTX_ ## ctx, err, ##__VA_ARGS__).stream()
|
|
||||||
|
|
||||||
#define LOG_CHECK_LEVEL(sev) WEBRTC_VLOG_IS_ON(rtc::sev)
|
#define LOG_CHECK_LEVEL(sev) CheckVlogIsOn(rtc::sev, __FILE__)
|
||||||
#define LOG_CHECK_LEVEL_V(sev) WEBRTC_VLOG_IS_ON(sev)
|
#define LOG_CHECK_LEVEL_V(sev) CheckVlogIsOn(sev, __FILE__)
|
||||||
|
|
||||||
#define LOG_V(sev) DIAGNOSTIC_LOG(sev, NONE, 0)
|
#define LOG_V(sev) DIAGNOSTIC_LOG(sev, NONE, 0)
|
||||||
#undef LOG
|
#undef LOG
|
||||||
|
Reference in New Issue
Block a user