diff --git a/rtc_base/logging.h b/rtc_base/logging.h index 93c2882633..83bc33a60b 100644 --- a/rtc_base/logging.h +++ b/rtc_base/logging.h @@ -61,6 +61,12 @@ #include "rtc_base/constructormagic.h" #include "rtc_base/thread_annotations.h" +#if !defined(NDEBUG) || defined(DLOG_ALWAYS_ON) +#define RTC_DLOG_IS_ON 1 +#else +#define RTC_DLOG_IS_ON 0 +#endif + namespace rtc { /////////////////////////////////////////////////////////////////////////////// @@ -360,7 +366,22 @@ inline bool LogCheckLevel(LoggingSeverity sev) { #define RTC_PLOG(sev, err) \ RTC_LOG_ERR_EX(sev, err) -// TODO(?): Add an "assert" wrapper that logs in the same manner. +// The RTC_DLOG macros are equivalent to their RTC_LOG counterparts except that +// they only generate code in debug builds. +#if RTC_DLOG_IS_ON +#define RTC_DLOG(sev) RTC_LOG(sev) +#define RTC_DLOG_V(sev) RTC_LOG_V(sev) +#define RTC_DLOG_F(sev) RTC_LOG_F(sev) +#else +#define RTC_DLOG_EAT_STREAM_PARAMS(sev) \ + (true ? true : ((void)(rtc::sev), true)) \ + ? static_cast(0) \ + : rtc::LogMessageVoidify() & \ + rtc::LogMessage(__FILE__, __LINE__, rtc::sev).stream() +#define RTC_DLOG(sev) RTC_DLOG_EAT_STREAM_PARAMS(sev) +#define RTC_DLOG_V(sev) RTC_DLOG_EAT_STREAM_PARAMS(sev) +#define RTC_DLOG_F(sev) RTC_DLOG_EAT_STREAM_PARAMS(sev) +#endif } // namespace rtc diff --git a/voice_engine/transmit_mixer.cc b/voice_engine/transmit_mixer.cc index bfee66e69b..049a64c2e8 100644 --- a/voice_engine/transmit_mixer.cc +++ b/voice_engine/transmit_mixer.cc @@ -32,8 +32,8 @@ TransmitMixer::Create(TransmitMixer*& mixer) mixer = new TransmitMixer(); if (mixer == NULL) { - RTC_LOG(LS_ERROR) << "TransmitMixer::Create() unable to allocate memory " - "for mixer"; + RTC_DLOG(LS_ERROR) << + "TransmitMixer::Create() unable to allocate memory for mixer"; return -1; } return 0; @@ -187,8 +187,8 @@ void TransmitMixer::ProcessAudio(int delay_ms, int clock_drift, GainControl* agc = audioproc_->gain_control(); if (agc->set_stream_analog_level(current_mic_level) != 0) { - RTC_LOG(LS_ERROR) << "set_stream_analog_level failed: current_mic_level = " - << current_mic_level; + RTC_DLOG(LS_ERROR) << "set_stream_analog_level failed: current_mic_level = " + << current_mic_level; assert(false); } @@ -201,7 +201,7 @@ void TransmitMixer::ProcessAudio(int delay_ms, int clock_drift, int err = audioproc_->ProcessStream(&_audioFrame); if (err != 0) { - RTC_LOG(LS_ERROR) << "ProcessStream() error: " << err; + RTC_DLOG(LS_ERROR) << "ProcessStream() error: " << err; assert(false); }