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.cc b/rtc_base/logging.cc
index 37d23ce..c87698a 100644
--- a/rtc_base/logging.cc
+++ b/rtc_base/logging.cc
@@ -81,6 +81,13 @@
 CriticalSection g_log_crit;
 }  // namespace
 
+// Inefficient default implementation, override is recommended.
+void LogSink::OnLogMessage(const std::string& msg,
+                           LoggingSeverity severity,
+                           const char* tag) {
+  OnLogMessage(tag + (": " + msg));
+}
+
 /////////////////////////////////////////////////////////////////////////////
 // LogMessage
 /////////////////////////////////////////////////////////////////////////////
@@ -126,8 +133,14 @@
     print_stream_ << "[" << std::dec << id << "] ";
   }
 
-  if (file != nullptr)
+  if (file != nullptr) {
+#if defined(WEBRTC_ANDROID)
+    tag_ = FilenameFromPath(file);
+    print_stream_ << "(line " << line << "): ";
+#else
     print_stream_ << "(" << FilenameFromPath(file) << ":" << line << "): ";
+#endif
+  }
 
   if (err_ctx != ERRCTX_NONE) {
     char tmp_buf[1024];
@@ -216,7 +229,11 @@
   CritScope cs(&g_log_crit);
   for (auto& kv : streams_) {
     if (severity_ >= kv.second) {
+#if defined(WEBRTC_ANDROID)
+      kv.first->OnLogMessage(str, severity_, tag_);
+#else
       kv.first->OnLogMessage(str);
+#endif
     }
   }
 }