Log to webrtc logging stream from java code.
Future log messages should all be sent to org.webrtc.Logging as well.
BUG=
Review URL: https://codereview.webrtc.org/1338033003
Cr-Original-Commit-Position: refs/heads/master@{#9936}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 66f0da2197974dcc1008f25df2bb4e1d463ad506
diff --git a/base/logging.cc b/base/logging.cc
index e2ee115..0bc3866 100644
--- a/base/logging.cc
+++ b/base/logging.cc
@@ -21,13 +21,14 @@
#include <CoreServices/CoreServices.h>
#elif defined(WEBRTC_ANDROID)
#include <android/log.h>
-static const char kLibjingle[] = "libjingle";
// Android has a 1024 limit on log inputs. We use 60 chars as an
// approx for the header/tag portion.
// See android/system/core/liblog/logd_write.c
static const int kMaxLogLineSize = 1024 - 60;
#endif // WEBRTC_MAC && !defined(WEBRTC_IOS) || WEBRTC_ANDROID
+static const char kLibjingle[] = "libjingle";
+
#include <time.h>
#include <limits.h>
@@ -114,6 +115,7 @@
LogMessage::LogMessage(const char* file, int line, LoggingSeverity sev,
LogErrorContext err_ctx, int err, const char* module)
: severity_(sev),
+ tag_(kLibjingle),
warn_slow_logs_delay_(WARN_SLOW_LOGS_DELAY) {
if (timestamp_) {
uint32 time = TimeSince(LogStartTime());
@@ -175,6 +177,14 @@
}
}
+LogMessage::LogMessage(const char* file,
+ int line,
+ LoggingSeverity sev,
+ const std::string& tag)
+ : LogMessage(file, line, sev, ERRCTX_NONE, 0 /* err */, NULL /* module */) {
+ tag_ = tag;
+}
+
LogMessage::~LogMessage() {
if (!extra_.empty())
print_stream_ << " : " << extra_;
@@ -182,7 +192,7 @@
const std::string& str = print_stream_.str();
if (severity_ >= dbg_sev_) {
- OutputToDebug(str, severity_);
+ OutputToDebug(str, severity_, tag_);
}
uint32 before = Time();
@@ -333,7 +343,8 @@
}
void LogMessage::OutputToDebug(const std::string& str,
- LoggingSeverity severity) {
+ LoggingSeverity severity,
+ const std::string& tag) {
bool log_to_stderr = log_to_stderr_;
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && (!defined(DEBUG) || defined(NDEBUG))
// On the Mac, all stderr output goes to the Console log and causes clutter.
@@ -377,7 +388,7 @@
int prio;
switch (severity) {
case LS_SENSITIVE:
- __android_log_write(ANDROID_LOG_INFO, kLibjingle, "SENSITIVE");
+ __android_log_write(ANDROID_LOG_INFO, tag.c_str(), "SENSITIVE");
if (log_to_stderr) {
fprintf(stderr, "SENSITIVE");
fflush(stderr);
@@ -404,13 +415,13 @@
int idx = 0;
const int max_lines = size / kMaxLogLineSize + 1;
if (max_lines == 1) {
- __android_log_print(prio, kLibjingle, "%.*s", size, str.c_str());
+ __android_log_print(prio, tag.c_str(), "%.*s", size, str.c_str());
} else {
while (size > 0) {
const int len = std::min(size, kMaxLogLineSize);
// Use the size of the string in the format (str may have \0 in the
// middle).
- __android_log_print(prio, kLibjingle, "[%d/%d] %.*s",
+ __android_log_print(prio, tag.c_str(), "[%d/%d] %.*s",
line + 1, max_lines,
len, str.c_str() + idx);
idx += len;
diff --git a/base/logging.h b/base/logging.h
index 4840dfe..67a350b 100644
--- a/base/logging.h
+++ b/base/logging.h
@@ -136,6 +136,12 @@
LogMessage(const char* file, int line, LoggingSeverity sev,
LogErrorContext err_ctx = ERRCTX_NONE, int err = 0,
const char* module = NULL);
+
+ LogMessage(const char* file,
+ int line,
+ LoggingSeverity sev,
+ const std::string& tag);
+
~LogMessage();
static inline bool Loggable(LoggingSeverity sev) { return (sev >= min_sev_); }
@@ -193,7 +199,9 @@
static void UpdateMinLogSeverity() EXCLUSIVE_LOCKS_REQUIRED(crit_);
// These write out the actual log messages.
- static void OutputToDebug(const std::string& msg, LoggingSeverity severity_);
+ static void OutputToDebug(const std::string& msg,
+ LoggingSeverity severity,
+ const std::string& tag);
// The ostream that buffers the formatted message before output
std::ostringstream print_stream_;
@@ -201,6 +209,9 @@
// The severity level of this message
LoggingSeverity severity_;
+ // The Android debug output tag.
+ std::string tag_;
+
// String data generated in the constructor, that should be appended to
// the message before output.
std::string extra_;
@@ -341,6 +352,10 @@
(errno)
#endif // WEBRTC_WIN
+#define LOG_TAG(sev, tag) \
+ LOG_SEVERITY_PRECONDITION(sev) \
+ rtc::LogMessage(__FILE__, __LINE__, sev, tag).stream()
+
#define PLOG(sev, err) \
LOG_ERR_EX(sev, err)