Revert "Consolidate loggability checks and replace streams."
This reverts commit 4092cd6db459ab8152588143b7b76e0946d2c433.
Reason for revert: Some g3 things depend on log macro implementation details.
Original change's description:
> 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: Ia4e3e12b34716d76c05807e44db1ed4a62dffb87
> Reviewed-on: https://webrtc-review.googlesource.com/97440
> Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
> Cr-Commit-Position: refs/heads/master@{#24547}
TBR=kwiberg@webrtc.org,jonasolsson@webrtc.org
Change-Id: I06f0a5b50c96c08a5e7be4d8d2bcb22d50c0179f
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: webrtc:8982
Reviewed-on: https://webrtc-review.googlesource.com/97720
Reviewed-by: Jonas Olsson <jonasolsson@webrtc.org>
Commit-Queue: Jonas Olsson <jonasolsson@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#24553}
diff --git a/rtc_base/logging.h b/rtc_base/logging.h
index 5f2aadb..b5af959 100644
--- a/rtc_base/logging.h
+++ b/rtc_base/logging.h
@@ -57,7 +57,6 @@
#include "rtc_base/constructormagic.h"
#include "rtc_base/deprecation.h"
-#include "rtc_base/strings/string_builder.h"
#include "rtc_base/system/inline.h"
#include "rtc_base/thread_annotations.h"
@@ -408,7 +407,18 @@
void AddTag(const char* tag);
- rtc::StringBuilder& stream();
+ static bool Loggable(LoggingSeverity sev);
+
+ // Same as the above, but using a template argument instead of a function
+ // argument. (When the logging severity is statically known, passing it as a
+ // template argument instead of as a function argument saves space at the
+ // call site.)
+ template <LoggingSeverity S>
+ RTC_NO_INLINE static bool Loggable() {
+ return Loggable(S);
+ }
+
+ std::ostream& stream();
// Returns the time at which this function was called for the first time.
// The time will be used as the logging start time.
@@ -454,12 +464,6 @@
// Useful for configuring logging from the command line.
static void ConfigureLogging(const char* params);
- // Checks the current global debug severity and if the |streams_| collection
- // is empty. If |severity| is smaller than the global severity and if the
- // |streams_| collection is empty, the LogMessage will be considered a noop
- // LogMessage.
- static bool IsNoop(LoggingSeverity severity);
-
private:
friend class LogMessageForTesting;
typedef std::pair<LogSink*, LoggingSeverity> StreamAndSeverity;
@@ -477,12 +481,18 @@
static void OutputToDebug(const std::string& msg, LoggingSeverity severity);
#endif
+ // Checks the current global debug severity and if the |streams_| collection
+ // is empty. If |severity| is smaller than the global severity and if the
+ // |streams_| collection is empty, the LogMessage will be considered a noop
+ // LogMessage.
+ static bool IsNoop(LoggingSeverity severity);
+
// Called from the dtor (or from a test) to append optional extra error
// information to the log stream and a newline character.
void FinishPrintStream();
- // The stringbuilder that buffers the formatted message before output
- rtc::StringBuilder print_stream_;
+ // The ostream that buffers the formatted message before output
+ std::ostringstream print_stream_;
// The severity level of this message
LoggingSeverity severity_;
@@ -496,6 +506,8 @@
// the message before output.
std::string extra_;
+ const bool is_noop_;
+
// The output streams and their associated severities
static StreamList streams_;
@@ -515,11 +527,13 @@
// DEPRECATED.
// TODO(bugs.webrtc.org/9278): Remove once there are no more users.
#define RTC_LOG_SEVERITY_PRECONDITION(sev) \
- (rtc::LogMessage::IsNoop(sev)) \
+ !(rtc::LogMessage::Loggable(sev)) \
? static_cast<void>(0) \
: rtc::webrtc_logging_impl::LogMessageVoidify()&
#define RTC_LOG(sev) \
+ for (bool do_log = rtc::LogMessage::Loggable<rtc::sev>(); do_log; \
+ do_log = false) \
rtc::webrtc_logging_impl::LogCall() & \
rtc::webrtc_logging_impl::LogStreamer<>() \
<< rtc::webrtc_logging_impl::LogMetadata(__FILE__, __LINE__, \
@@ -527,6 +541,7 @@
// The _V version is for when a variable is passed in.
#define RTC_LOG_V(sev) \
+ for (bool do_log = rtc::LogMessage::Loggable(sev); do_log; do_log = false) \
rtc::webrtc_logging_impl::LogCall() & \
rtc::webrtc_logging_impl::LogStreamer<>() \
<< rtc::webrtc_logging_impl::LogMetadata(__FILE__, __LINE__, sev)
@@ -549,6 +564,8 @@
}
#define RTC_LOG_E(sev, ctx, err) \
+ for (bool do_log = rtc::LogMessage::Loggable<rtc::sev>(); do_log; \
+ do_log = false) \
rtc::webrtc_logging_impl::LogCall() & \
rtc::webrtc_logging_impl::LogStreamer<>() \
<< rtc::webrtc_logging_impl::LogMetadataErr { \
@@ -586,6 +603,7 @@
} // namespace webrtc_logging_impl
#define RTC_LOG_TAG(sev, tag) \
+ for (bool do_log = rtc::LogMessage::Loggable(sev); do_log; do_log = false) \
rtc::webrtc_logging_impl::LogCall() & \
rtc::webrtc_logging_impl::LogStreamer<>() \
<< rtc::webrtc_logging_impl::LogMetadataTag { \