mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Check if logging for a severity is enabled at the call site.
This does mean that each call site becomes slightly more expensive in terms of binary size, but until we have a better way to mitigate the perf impact, I think we'll have to live with it. We could also consider migrating LS_VERBOSE over to RTC_DLOG. Bug: webrtc:11968 Change-Id: Ib16f1109366ffaa88b8df28ebfa5bc3b539f691f Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/184922 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Tommi <tommi@webrtc.org> Cr-Commit-Position: refs/heads/master@{#32153}
This commit is contained in:
parent
52fa992ccc
commit
edd7f9e94d
3 changed files with 19 additions and 10 deletions
|
@ -486,11 +486,6 @@ void Log(const LogArgType* fmt, ...) {
|
|||
}
|
||||
}
|
||||
|
||||
if (LogMessage::IsNoop(meta.meta.Severity())) {
|
||||
va_end(args);
|
||||
return;
|
||||
}
|
||||
|
||||
LogMessage log_message(meta.meta.File(), meta.meta.Line(),
|
||||
meta.meta.Severity(), meta.err_ctx, meta.err);
|
||||
if (tag) {
|
||||
|
|
|
@ -598,10 +598,10 @@ class LogMessage {
|
|||
// Logging Helpers
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define RTC_LOG_FILE_LINE(sev, file, line) \
|
||||
RTC_LOG_ENABLED() && \
|
||||
::rtc::webrtc_logging_impl::LogCall() & \
|
||||
::rtc::webrtc_logging_impl::LogStreamer<>() \
|
||||
#define RTC_LOG_FILE_LINE(sev, file, line) \
|
||||
RTC_LOG_ENABLED() && !rtc::LogMessage::IsNoop(sev) && \
|
||||
::rtc::webrtc_logging_impl::LogCall() & \
|
||||
::rtc::webrtc_logging_impl::LogStreamer<>() \
|
||||
<< ::rtc::webrtc_logging_impl::LogMetadata(file, line, sev)
|
||||
|
||||
#define RTC_LOG(sev) RTC_LOG_FILE_LINE(::rtc::sev, __FILE__, __LINE__)
|
||||
|
|
|
@ -359,5 +359,19 @@ TEST(LogTest, EnumsAreSupported) {
|
|||
stream.Close();
|
||||
}
|
||||
|
||||
TEST(LogTest, NoopSeverityDoesNotRunStringFormatting) {
|
||||
if (!LogMessage::IsNoop(LS_VERBOSE)) {
|
||||
RTC_LOG(LS_WARNING) << "Skipping test since verbose logging is turned on.";
|
||||
return;
|
||||
}
|
||||
bool was_called = false;
|
||||
auto cb = [&was_called]() {
|
||||
was_called = true;
|
||||
return "This could be an expensive callback.";
|
||||
};
|
||||
RTC_LOG(LS_VERBOSE) << "This should not be logged: " << cb();
|
||||
EXPECT_FALSE(was_called);
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
#endif
|
||||
#endif // RTC_LOG_ENABLED()
|
||||
|
|
Loading…
Reference in a new issue