Add OnLogMessage(msg, sev, tag) to logsinks
This fixes a bug where tags are not saved by FileRotatingLogSink.
It is also a preparation step for injectable logging.
Bug: webrtc:9225
Change-Id: I06ae0810073492bd2f103fefd64bd3cd02659fbc
Reviewed-on: https://webrtc-review.googlesource.com/84361
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Sami Kalliomäki <sakal@webrtc.org>
Commit-Queue: Paulina Hensman <phensman@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#23695}
diff --git a/rtc_base/logging_unittest.cc b/rtc_base/logging_unittest.cc
index 8f96095..44d5805 100644
--- a/rtc_base/logging_unittest.cc
+++ b/rtc_base/logging_unittest.cc
@@ -45,6 +45,9 @@
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
// Returns the contents of the internal log stream.
// Note that parts of the stream won't (as is) be available until *after* the
@@ -215,9 +218,28 @@
log_msg.stream() << "<- Does this look right?";
const std::string stream = log_msg.GetPrintStream();
+#if defined(WEBRTC_ANDROID)
+ const char* tag = log_msg.get_tag();
+ EXPECT_NE(nullptr, strstr(tag, "myfile.cc"));
+ EXPECT_NE(std::string::npos, stream.find("100"));
+#else
EXPECT_NE(std::string::npos, stream.find("(myfile.cc:100)"));
+#endif
}
+#if defined(WEBRTC_ANDROID)
+TEST(LogTest, CheckTagAddedToStringInDefaultOnLogMessageAndroid) {
+ std::string str;
+ LogSinkImpl<StringStream> stream(&str);
+ LogMessage::AddLogToStream(&stream, LS_INFO);
+ EXPECT_EQ(LS_INFO, LogMessage::GetLogToStream(&stream));
+
+ RTC_LOG_TAG(LS_INFO, "my_tag") << "INFO";
+ EXPECT_NE(std::string::npos, str.find("INFO"));
+ EXPECT_NE(std::string::npos, str.find("my_tag"));
+}
+#endif
+
TEST(LogTest, CheckNoopLogEntry) {
if (LogMessage::GetLogToDebug() <= LS_SENSITIVE) {
printf("CheckNoopLogEntry: skipping. Global severity is being overridden.");