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}
diff --git a/rtc_base/logging_unittest.cc b/rtc_base/logging_unittest.cc index a66f8b5..6bb20ab 100644 --- a/rtc_base/logging_unittest.cc +++ b/rtc_base/logging_unittest.cc
@@ -359,5 +359,19 @@ 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()