Reland "Consolidate loggability checks and replace streams."

Currently we check if a message should be printed at the call site using LogMessage::Loggable, in the LogMessage itself using LogMessage::IsNoop and in LogMessage::OutputToDebug using log_to_stderr_.

This change unifies the first two of these into a early return in Log().

Bug: webrtc:8982
Change-Id: I462b1cf63c44fec46e5c59b147b2b99605aaae0c
Reviewed-on: https://webrtc-review.googlesource.com/98820
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24630}
diff --git a/rtc_base/logging_unittest.cc b/rtc_base/logging_unittest.cc
index af51212..263e992 100644
--- a/rtc_base/logging_unittest.cc
+++ b/rtc_base/logging_unittest.cc
@@ -150,7 +150,6 @@
       : LogMessage(file, line, sev, err_ctx, err) {}
 
   const std::string& get_extra() const { return extra_; }
-  bool is_noop() const { return is_noop_; }
 #if defined(WEBRTC_ANDROID)
   const char* get_tag() const { return tag_; }
 #endif
@@ -163,10 +162,7 @@
     RTC_DCHECK(!is_finished_);
     is_finished_ = true;
     FinishPrintStream();
-    std::string ret = print_stream_.str();
-    // Just to make an error even more clear if the stream gets used after this.
-    print_stream_.clear();
-    return ret;
+    return print_stream_.Release();
   }
 
  private:
@@ -303,7 +299,6 @@
 TEST(LogTest, CheckExtraErrorField) {
   LogMessageForTesting log_msg("some/path/myfile.cc", 100, LS_WARNING,
                                ERRCTX_ERRNO, 0xD);
-  ASSERT_FALSE(log_msg.is_noop());
   log_msg.stream() << "This gets added at dtor time";
 
   const std::string& extra = log_msg.get_extra();
@@ -314,7 +309,6 @@
 
 TEST(LogTest, CheckFilePathParsed) {
   LogMessageForTesting log_msg("some/path/myfile.cc", 100, LS_INFO);
-  ASSERT_FALSE(log_msg.is_noop());
   log_msg.stream() << "<- Does this look right?";
 
   const std::string stream = log_msg.GetPrintStream();
@@ -340,21 +334,6 @@
 }
 #endif
 
-TEST(LogTest, CheckNoopLogEntry) {
-  if (LogMessage::GetLogToDebug() <= LS_SENSITIVE) {
-    printf("CheckNoopLogEntry: skipping. Global severity is being overridden.");
-    return;
-  }
-
-  // Logging at LS_SENSITIVE severity, is by default turned off, so this should
-  // be treated as a noop message.
-  LogMessageForTesting log_msg("some/path/myfile.cc", 100, LS_SENSITIVE);
-  log_msg.stream() << "Should be logged to nowhere.";
-  EXPECT_TRUE(log_msg.is_noop());
-  const std::string stream = log_msg.GetPrintStream();
-  EXPECT_TRUE(stream.empty());
-}
-
 // Test the time required to write 1000 80-character logs to a string.
 TEST(LogTest, Perf) {
   std::string str;
@@ -363,10 +342,7 @@
 
   const std::string message(80, 'X');
   {
-    // Just to be sure that we're not measuring the performance of logging
-    // noop log messages.
     LogMessageForTesting sanity_check_msg(__FILE__, __LINE__, LS_SENSITIVE);
-    ASSERT_FALSE(sanity_check_msg.is_noop());
   }
 
   // We now know how many bytes the logging framework will tag onto every msg.