Injectable logging
Allows passing a Loggable to PCFactory.initializationOptions, which is then injected to Logging.java and logging.h. Future log messages in both Java and native will then be passed to this Loggable. Bug: webrtc:9225 Change-Id: I2ff693380639448301a78a93dc11d3a0106f0967 Reviewed-on: https://webrtc-review.googlesource.com/73243 Commit-Queue: Paulina Hensman <phensman@webrtc.org> Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Reviewed-by: Sami Kalliomäki <sakal@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23241}
This commit is contained in:
committed by
Commit Bot
parent
8694f29b30
commit
59216ec4a4
@ -1342,7 +1342,10 @@ if (is_android) {
|
|||||||
rtc_android_library("base_java") {
|
rtc_android_library("base_java") {
|
||||||
java_files = [
|
java_files = [
|
||||||
"java/src/org/webrtc/ContextUtils.java",
|
"java/src/org/webrtc/ContextUtils.java",
|
||||||
|
"java/src/org/webrtc/FallbackLogger.java",
|
||||||
|
"java/src/org/webrtc/Loggable.java",
|
||||||
"java/src/org/webrtc/Logging.java",
|
"java/src/org/webrtc/Logging.java",
|
||||||
|
"java/src/org/webrtc/NativeLogger.java",
|
||||||
"java/src/org/webrtc/Size.java",
|
"java/src/org/webrtc/Size.java",
|
||||||
"java/src/org/webrtc/ThreadUtils.java",
|
"java/src/org/webrtc/ThreadUtils.java",
|
||||||
]
|
]
|
||||||
|
|||||||
45
rtc_base/java/src/org/webrtc/FallbackLogger.java
Normal file
45
rtc_base/java/src/org/webrtc/FallbackLogger.java
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.webrtc;
|
||||||
|
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import org.webrtc.Loggable;
|
||||||
|
import org.webrtc.Logging.Severity;
|
||||||
|
|
||||||
|
class FallbackLogger implements Loggable {
|
||||||
|
final Logger fallbackLogger;
|
||||||
|
|
||||||
|
public FallbackLogger() {
|
||||||
|
fallbackLogger = Logger.getLogger("org.webrtc.FallbackLogger");
|
||||||
|
fallbackLogger.setLevel(Level.ALL);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLogMessage(String message, Severity severity, String tag) {
|
||||||
|
Level level;
|
||||||
|
switch (severity) {
|
||||||
|
case LS_ERROR:
|
||||||
|
level = Level.SEVERE;
|
||||||
|
break;
|
||||||
|
case LS_WARNING:
|
||||||
|
level = Level.WARNING;
|
||||||
|
break;
|
||||||
|
case LS_INFO:
|
||||||
|
level = Level.INFO;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
level = Level.FINE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
fallbackLogger.log(level, tag + ": " + message);
|
||||||
|
}
|
||||||
|
}
|
||||||
22
rtc_base/java/src/org/webrtc/Loggable.java
Normal file
22
rtc_base/java/src/org/webrtc/Loggable.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.webrtc;
|
||||||
|
|
||||||
|
import org.webrtc.Logging.Severity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Java interface for WebRTC logging. The default implementation uses webrtc.Logging.
|
||||||
|
*
|
||||||
|
* When injected, the Loggable will receive logging from both Java and native.
|
||||||
|
*/
|
||||||
|
public interface Loggable {
|
||||||
|
public void onLogMessage(String message, Severity severity, String tag);
|
||||||
|
}
|
||||||
@ -13,28 +13,31 @@ package org.webrtc;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.logging.Level;
|
import org.webrtc.Loggable;
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java wrapper for WebRTC logging. Logging defaults to java.util.logging.Logger, but will switch to
|
* Java wrapper for WebRTC logging. Logging defaults to java.util.logging.Logger, but a custom
|
||||||
* native logging (rtc::LogMessage) if one of the following static functions are called from the
|
* logger implementing the Loggable interface can be injected along with a Severity. All subsequent
|
||||||
* app:
|
* log messages will then be redirected to the injected Loggable, except those with a severity lower
|
||||||
* - Logging.enableLogThreads
|
* than the specified severity, which will be discarded.
|
||||||
* - Logging.enableLogTimeStamps
|
|
||||||
* - Logging.enableLogToDebugOutput
|
|
||||||
*
|
*
|
||||||
* Using these APIs requires that the native library is loaded, using
|
* Injecting a Loggable or using any of the enable... methods requires that the native library is
|
||||||
* PeerConnectionFactory.initialize.
|
* loaded, using PeerConnectionFactory.initialize.
|
||||||
*/
|
*/
|
||||||
public class Logging {
|
public class Logging {
|
||||||
private static final Logger fallbackLogger = createFallbackLogger();
|
private static Loggable loggable = new FallbackLogger();
|
||||||
private static volatile boolean loggingEnabled;
|
private static Severity loggableSeverity = Severity.LS_SENSITIVE;
|
||||||
|
|
||||||
private static Logger createFallbackLogger() {
|
static void injectLoggable(Loggable injectedLoggable, Severity severity) {
|
||||||
final Logger fallbackLogger = Logger.getLogger("org.webrtc.Logging");
|
if (injectedLoggable != null) {
|
||||||
fallbackLogger.setLevel(Level.ALL);
|
loggable = injectedLoggable;
|
||||||
return fallbackLogger;
|
loggableSeverity = severity;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void deleteInjectedLoggable() {
|
||||||
|
loggable = new FallbackLogger();
|
||||||
|
loggableSeverity = Severity.LS_SENSITIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(solenberg): Remove once dependent projects updated.
|
// TODO(solenberg): Remove once dependent projects updated.
|
||||||
@ -83,33 +86,16 @@ public class Logging {
|
|||||||
// TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression.
|
// TODO(bugs.webrtc.org/8491): Remove NoSynchronizedMethodCheck suppression.
|
||||||
@SuppressWarnings("NoSynchronizedMethodCheck")
|
@SuppressWarnings("NoSynchronizedMethodCheck")
|
||||||
public static synchronized void enableLogToDebugOutput(Severity severity) {
|
public static synchronized void enableLogToDebugOutput(Severity severity) {
|
||||||
nativeEnableLogToDebugOutput(severity.ordinal());
|
loggable = new NativeLogger(severity);
|
||||||
loggingEnabled = true;
|
loggableSeverity = severity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void log(Severity severity, String tag, String message) {
|
public static void log(Severity severity, String tag, String message) {
|
||||||
if (loggingEnabled) {
|
// Filter log messages below loggableSeverity.
|
||||||
nativeLog(severity.ordinal(), tag, message);
|
if (severity.ordinal() < loggableSeverity.ordinal()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
loggable.onLogMessage(message, severity, tag);
|
||||||
// Fallback to system log.
|
|
||||||
Level level;
|
|
||||||
switch (severity) {
|
|
||||||
case LS_ERROR:
|
|
||||||
level = Level.SEVERE;
|
|
||||||
break;
|
|
||||||
case LS_WARNING:
|
|
||||||
level = Level.WARNING;
|
|
||||||
break;
|
|
||||||
case LS_INFO:
|
|
||||||
level = Level.INFO;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
level = Level.FINE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
fallbackLogger.log(level, tag + ": " + message);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void d(String tag, String message) {
|
public static void d(String tag, String message) {
|
||||||
@ -151,8 +137,6 @@ public class Logging {
|
|||||||
return sw.toString();
|
return sw.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native void nativeEnableLogToDebugOutput(int nativeSeverity);
|
|
||||||
private static native void nativeEnableLogThreads();
|
private static native void nativeEnableLogThreads();
|
||||||
private static native void nativeEnableLogTimeStamps();
|
private static native void nativeEnableLogTimeStamps();
|
||||||
private static native void nativeLog(int severity, String tag, String message);
|
|
||||||
}
|
}
|
||||||
|
|||||||
28
rtc_base/java/src/org/webrtc/NativeLogger.java
Normal file
28
rtc_base/java/src/org/webrtc/NativeLogger.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.webrtc;
|
||||||
|
|
||||||
|
import org.webrtc.Loggable;
|
||||||
|
import org.webrtc.Logging.Severity;
|
||||||
|
|
||||||
|
class NativeLogger implements Loggable {
|
||||||
|
public NativeLogger(Severity severity) {
|
||||||
|
nativeEnableLogToDebugOutput(severity.ordinal());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLogMessage(String message, Severity severity, String tag) {
|
||||||
|
nativeLog(severity.ordinal(), tag, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static native void nativeEnableLogToDebugOutput(int nativeSeverity);
|
||||||
|
private static native void nativeLog(int severity, String tag, String message);
|
||||||
|
}
|
||||||
@ -80,6 +80,11 @@ std::ostream& GetNoopStream() {
|
|||||||
CriticalSection g_log_crit;
|
CriticalSection g_log_crit;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
void LogSink::OnLogMessage(const std::string& msg,
|
||||||
|
LoggingSeverity severity,
|
||||||
|
const char* tag) {
|
||||||
|
OnLogMessage(msg);
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
// LogMessage
|
// LogMessage
|
||||||
@ -126,8 +131,14 @@ LogMessage::LogMessage(const char* file,
|
|||||||
print_stream_ << "[" << std::dec << id << "] ";
|
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 << "): ";
|
print_stream_ << "(" << FilenameFromPath(file) << ":" << line << "): ";
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
if (err_ctx != ERRCTX_NONE) {
|
if (err_ctx != ERRCTX_NONE) {
|
||||||
char tmp_buf[1024];
|
char tmp_buf[1024];
|
||||||
@ -180,7 +191,6 @@ LogMessage::LogMessage(const char* file,
|
|||||||
0 /* err */) {
|
0 /* err */) {
|
||||||
if (!is_noop_) {
|
if (!is_noop_) {
|
||||||
tag_ = tag;
|
tag_ = tag;
|
||||||
print_stream_ << tag << ": ";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -218,7 +228,11 @@ LogMessage::~LogMessage() {
|
|||||||
CritScope cs(&g_log_crit);
|
CritScope cs(&g_log_crit);
|
||||||
for (auto& kv : streams_) {
|
for (auto& kv : streams_) {
|
||||||
if (severity_ >= kv.second) {
|
if (severity_ >= kv.second) {
|
||||||
|
#if defined(WEBRTC_ANDROID)
|
||||||
|
kv.first->OnLogMessage(str, severity_, tag_);
|
||||||
|
#else
|
||||||
kv.first->OnLogMessage(str);
|
kv.first->OnLogMessage(str);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -117,6 +117,9 @@ class LogSink {
|
|||||||
public:
|
public:
|
||||||
LogSink() {}
|
LogSink() {}
|
||||||
virtual ~LogSink() {}
|
virtual ~LogSink() {}
|
||||||
|
virtual void OnLogMessage(const std::string& msg,
|
||||||
|
LoggingSeverity severity,
|
||||||
|
const char* tag);
|
||||||
virtual void OnLogMessage(const std::string& message) = 0;
|
virtual void OnLogMessage(const std::string& message) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -243,7 +246,7 @@ class LogMessage {
|
|||||||
LoggingSeverity severity_;
|
LoggingSeverity severity_;
|
||||||
|
|
||||||
#if defined(WEBRTC_ANDROID)
|
#if defined(WEBRTC_ANDROID)
|
||||||
// The Android debug output tag.
|
// The default Android debug output tag.
|
||||||
const char* tag_ = "libjingle";
|
const char* tag_ = "libjingle";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -47,6 +47,9 @@ class LogMessageForTesting : public LogMessage {
|
|||||||
|
|
||||||
const std::string& get_extra() const { return extra_; }
|
const std::string& get_extra() const { return extra_; }
|
||||||
bool is_noop() const { return is_noop_; }
|
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.
|
// Returns the contents of the internal log stream.
|
||||||
// Note that parts of the stream won't (as is) be available until *after* the
|
// Note that parts of the stream won't (as is) be available until *after* the
|
||||||
@ -186,7 +189,13 @@ TEST(LogTest, CheckFilePathParsed) {
|
|||||||
log_msg.stream() << "<- Does this look right?";
|
log_msg.stream() << "<- Does this look right?";
|
||||||
|
|
||||||
const std::string stream = log_msg.GetPrintStream();
|
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)"));
|
EXPECT_NE(std::string::npos, stream.find("(myfile.cc:100)"));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(LogTest, CheckNoopLogEntry) {
|
TEST(LogTest, CheckNoopLogEntry) {
|
||||||
|
|||||||
@ -89,7 +89,9 @@ rtc_source_set("base_jni") {
|
|||||||
"src/jni/jni_helpers.cc",
|
"src/jni/jni_helpers.cc",
|
||||||
"src/jni/jni_helpers.h",
|
"src/jni/jni_helpers.h",
|
||||||
"src/jni/pc/audio.h",
|
"src/jni/pc/audio.h",
|
||||||
|
"src/jni/pc/logging.cc",
|
||||||
"src/jni/pc/media.h",
|
"src/jni/pc/media.h",
|
||||||
|
"src/jni/pc/native_logger.cc",
|
||||||
"src/jni/pc/video.h",
|
"src/jni/pc/video.h",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -508,6 +510,38 @@ generate_jni("generated_peerconnection_jni") {
|
|||||||
jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h"
|
jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rtc_android_library("logging_java") {
|
||||||
|
java_files = [ "src/java/org/webrtc/JNILogging.java" ]
|
||||||
|
|
||||||
|
deps = [
|
||||||
|
":base_java",
|
||||||
|
"//rtc_base:base_java",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
generate_jni("generated_logging_jni") {
|
||||||
|
sources = [
|
||||||
|
"src/java/org/webrtc/JNILogging.java",
|
||||||
|
]
|
||||||
|
jni_package = ""
|
||||||
|
jni_generator_include = "//sdk/android/src/jni/jni_generator_helper.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
rtc_static_library("logging_jni") {
|
||||||
|
visibility = [ "*" ]
|
||||||
|
sources = [
|
||||||
|
"src/jni/logging/logsink.cc",
|
||||||
|
"src/jni/logging/logsink.h",
|
||||||
|
]
|
||||||
|
|
||||||
|
deps = [
|
||||||
|
":base_jni",
|
||||||
|
":generated_logging_jni",
|
||||||
|
":native_api_jni",
|
||||||
|
"../../rtc_base:rtc_base",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
rtc_static_library("peerconnection_jni") {
|
rtc_static_library("peerconnection_jni") {
|
||||||
# Do not depend on this target externally unless you absolute have to. It is
|
# Do not depend on this target externally unless you absolute have to. It is
|
||||||
# made public because we don't have a proper NDK yet. Header APIs here are not
|
# made public because we don't have a proper NDK yet. Header APIs here are not
|
||||||
@ -524,7 +558,6 @@ rtc_static_library("peerconnection_jni") {
|
|||||||
"src/jni/pc/dtmfsender.cc",
|
"src/jni/pc/dtmfsender.cc",
|
||||||
"src/jni/pc/icecandidate.cc",
|
"src/jni/pc/icecandidate.cc",
|
||||||
"src/jni/pc/icecandidate.h",
|
"src/jni/pc/icecandidate.h",
|
||||||
"src/jni/pc/logging.cc",
|
|
||||||
"src/jni/pc/mediaconstraints.cc",
|
"src/jni/pc/mediaconstraints.cc",
|
||||||
"src/jni/pc/mediaconstraints.h",
|
"src/jni/pc/mediaconstraints.h",
|
||||||
"src/jni/pc/mediasource.cc",
|
"src/jni/pc/mediasource.cc",
|
||||||
@ -582,6 +615,7 @@ rtc_static_library("peerconnection_jni") {
|
|||||||
":base_jni",
|
":base_jni",
|
||||||
":generated_external_classes_jni",
|
":generated_external_classes_jni",
|
||||||
":generated_peerconnection_jni",
|
":generated_peerconnection_jni",
|
||||||
|
":logging_jni",
|
||||||
":native_api_jni",
|
":native_api_jni",
|
||||||
"../..:webrtc_common",
|
"../..:webrtc_common",
|
||||||
"../../api:libjingle_peerconnection_api",
|
"../../api:libjingle_peerconnection_api",
|
||||||
@ -707,6 +741,7 @@ dist_jar("libwebrtc") {
|
|||||||
":java_audio_device_module_java",
|
":java_audio_device_module_java",
|
||||||
":libjingle_peerconnection_java",
|
":libjingle_peerconnection_java",
|
||||||
":libjingle_peerconnection_metrics_default_java",
|
":libjingle_peerconnection_metrics_default_java",
|
||||||
|
":logging_java",
|
||||||
":peerconnection_java",
|
":peerconnection_java",
|
||||||
":screencapturer_java",
|
":screencapturer_java",
|
||||||
":surfaceviewrenderer_java",
|
":surfaceviewrenderer_java",
|
||||||
@ -1001,6 +1036,7 @@ rtc_android_library("peerconnection_java") {
|
|||||||
deps = [
|
deps = [
|
||||||
":audio_api_java",
|
":audio_api_java",
|
||||||
":base_java",
|
":base_java",
|
||||||
|
":logging_java",
|
||||||
":video_api_java",
|
":video_api_java",
|
||||||
":video_java", # TODO(sakal): Remove dependency.
|
":video_java", # TODO(sakal): Remove dependency.
|
||||||
"//modules/audio_device:audio_device_java",
|
"//modules/audio_device:audio_device_java",
|
||||||
|
|||||||
@ -13,6 +13,7 @@ package org.webrtc;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import org.webrtc.Logging.Severity;
|
||||||
import org.webrtc.audio.AudioDeviceModule;
|
import org.webrtc.audio.AudioDeviceModule;
|
||||||
import org.webrtc.audio.LegacyAudioDeviceModule;
|
import org.webrtc.audio.LegacyAudioDeviceModule;
|
||||||
|
|
||||||
@ -42,15 +43,20 @@ public class PeerConnectionFactory {
|
|||||||
final boolean enableInternalTracer;
|
final boolean enableInternalTracer;
|
||||||
final boolean enableVideoHwAcceleration;
|
final boolean enableVideoHwAcceleration;
|
||||||
final NativeLibraryLoader nativeLibraryLoader;
|
final NativeLibraryLoader nativeLibraryLoader;
|
||||||
|
@Nullable Loggable loggable;
|
||||||
|
@Nullable Severity loggableSeverity;
|
||||||
|
|
||||||
private InitializationOptions(Context applicationContext, String fieldTrials,
|
private InitializationOptions(Context applicationContext, String fieldTrials,
|
||||||
boolean enableInternalTracer, boolean enableVideoHwAcceleration,
|
boolean enableInternalTracer, boolean enableVideoHwAcceleration,
|
||||||
NativeLibraryLoader nativeLibraryLoader) {
|
NativeLibraryLoader nativeLibraryLoader, @Nullable Loggable loggable,
|
||||||
|
@Nullable Severity loggableSeverity) {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
this.fieldTrials = fieldTrials;
|
this.fieldTrials = fieldTrials;
|
||||||
this.enableInternalTracer = enableInternalTracer;
|
this.enableInternalTracer = enableInternalTracer;
|
||||||
this.enableVideoHwAcceleration = enableVideoHwAcceleration;
|
this.enableVideoHwAcceleration = enableVideoHwAcceleration;
|
||||||
this.nativeLibraryLoader = nativeLibraryLoader;
|
this.nativeLibraryLoader = nativeLibraryLoader;
|
||||||
|
this.loggable = loggable;
|
||||||
|
this.loggableSeverity = loggableSeverity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder(Context applicationContext) {
|
public static Builder builder(Context applicationContext) {
|
||||||
@ -63,6 +69,8 @@ public class PeerConnectionFactory {
|
|||||||
private boolean enableInternalTracer = false;
|
private boolean enableInternalTracer = false;
|
||||||
private boolean enableVideoHwAcceleration = true;
|
private boolean enableVideoHwAcceleration = true;
|
||||||
private NativeLibraryLoader nativeLibraryLoader = new NativeLibrary.DefaultLoader();
|
private NativeLibraryLoader nativeLibraryLoader = new NativeLibrary.DefaultLoader();
|
||||||
|
@Nullable private Loggable loggable = null;
|
||||||
|
@Nullable private Severity loggableSeverity = null;
|
||||||
|
|
||||||
Builder(Context applicationContext) {
|
Builder(Context applicationContext) {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
@ -88,9 +96,16 @@ public class PeerConnectionFactory {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder setInjectableLogger(Loggable loggable, Severity severity) {
|
||||||
|
this.loggable = loggable;
|
||||||
|
this.loggableSeverity = severity;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public PeerConnectionFactory.InitializationOptions createInitializationOptions() {
|
public PeerConnectionFactory.InitializationOptions createInitializationOptions() {
|
||||||
return new PeerConnectionFactory.InitializationOptions(applicationContext, fieldTrials,
|
return new PeerConnectionFactory.InitializationOptions(applicationContext, fieldTrials,
|
||||||
enableInternalTracer, enableVideoHwAcceleration, nativeLibraryLoader);
|
enableInternalTracer, enableVideoHwAcceleration, nativeLibraryLoader, loggable,
|
||||||
|
loggableSeverity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,6 +215,13 @@ public class PeerConnectionFactory {
|
|||||||
if (options.enableInternalTracer && !internalTracerInitialized) {
|
if (options.enableInternalTracer && !internalTracerInitialized) {
|
||||||
initializeInternalTracer();
|
initializeInternalTracer();
|
||||||
}
|
}
|
||||||
|
if (options.loggable != null) {
|
||||||
|
Logging.injectLoggable(options.loggable, options.loggableSeverity);
|
||||||
|
nativeInjectLoggable(new JNILogging(options.loggable), options.loggableSeverity.ordinal());
|
||||||
|
} else {
|
||||||
|
Logging.deleteInjectedLoggable();
|
||||||
|
nativeDeleteLoggable();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkInitializeHasBeenCalled() {
|
private void checkInitializeHasBeenCalled() {
|
||||||
@ -475,4 +497,6 @@ public class PeerConnectionFactory {
|
|||||||
private static native void nativeInvokeThreadsCallbacks(long factory);
|
private static native void nativeInvokeThreadsCallbacks(long factory);
|
||||||
private static native void nativeFreeFactory(long factory);
|
private static native void nativeFreeFactory(long factory);
|
||||||
private static native long nativeGetNativePeerConnectionFactory(long factory);
|
private static native long nativeGetNativePeerConnectionFactory(long factory);
|
||||||
|
private static native void nativeInjectLoggable(JNILogging jniLogging, int severity);
|
||||||
|
private static native void nativeDeleteLoggable();
|
||||||
}
|
}
|
||||||
|
|||||||
28
sdk/android/src/java/org/webrtc/JNILogging.java
Normal file
28
sdk/android/src/java/org/webrtc/JNILogging.java
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC Project Authors. All rights reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.webrtc;
|
||||||
|
|
||||||
|
import org.webrtc.CalledByNative;
|
||||||
|
import org.webrtc.Loggable;
|
||||||
|
import org.webrtc.Logging.Severity;
|
||||||
|
|
||||||
|
class JNILogging {
|
||||||
|
private final Loggable loggable;
|
||||||
|
|
||||||
|
public JNILogging(Loggable loggable) {
|
||||||
|
this.loggable = loggable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@CalledByNative
|
||||||
|
public void logToInjectable(String message, Integer severity, String tag) {
|
||||||
|
loggable.onLogMessage(message, Severity.values()[severity], tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
35
sdk/android/src/jni/logging/logsink.cc
Normal file
35
sdk/android/src/jni/logging/logsink.cc
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC Project Authors. All rights reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
#include "sdk/android/src/jni/logging/logsink.h"
|
||||||
|
|
||||||
|
#include "sdk/android/generated_logging_jni/jni/JNILogging_jni.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
namespace jni {
|
||||||
|
|
||||||
|
JNILogSink::JNILogSink(JNIEnv* env, const JavaRef<jobject>& j_logging)
|
||||||
|
: j_logging_(env, j_logging) {}
|
||||||
|
JNILogSink::~JNILogSink() = default;
|
||||||
|
|
||||||
|
void JNILogSink::OnLogMessage(const std::string& msg,
|
||||||
|
rtc::LoggingSeverity severity,
|
||||||
|
const char* tag) {
|
||||||
|
JNIEnv* env = AttachCurrentThreadIfNeeded();
|
||||||
|
Java_JNILogging_logToInjectable(env, j_logging_, NativeToJavaString(env, msg),
|
||||||
|
NativeToJavaInteger(env, severity),
|
||||||
|
NativeToJavaString(env, tag));
|
||||||
|
}
|
||||||
|
|
||||||
|
void JNILogSink::OnLogMessage(const std::string& msg) {
|
||||||
|
RTC_NOTREACHED();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace jni
|
||||||
|
} // namespace webrtc
|
||||||
39
sdk/android/src/jni/logging/logsink.h
Normal file
39
sdk/android/src/jni/logging/logsink.h
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
#ifndef SDK_ANDROID_SRC_JNI_LOGGING_LOGSINK_H_
|
||||||
|
#define SDK_ANDROID_SRC_JNI_LOGGING_LOGSINK_H_
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "rtc_base/logging.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
namespace jni {
|
||||||
|
|
||||||
|
class JNILogSink : public rtc::LogSink {
|
||||||
|
public:
|
||||||
|
JNILogSink(JNIEnv* env, const JavaRef<jobject>& j_logging);
|
||||||
|
~JNILogSink() override;
|
||||||
|
|
||||||
|
void OnLogMessage(const std::string& msg,
|
||||||
|
rtc::LoggingSeverity severity,
|
||||||
|
const char* tag) override;
|
||||||
|
void OnLogMessage(const std::string& msg) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
const ScopedJavaGlobalRef<jobject> j_logging_;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace jni
|
||||||
|
} // namespace webrtc
|
||||||
|
|
||||||
|
#endif // SDK_ANDROID_SRC_JNI_LOGGING_LOGSINK_H_
|
||||||
@ -17,17 +17,6 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace jni {
|
namespace jni {
|
||||||
|
|
||||||
JNI_FUNCTION_DECLARATION(void,
|
|
||||||
Logging_nativeEnableLogToDebugOutput,
|
|
||||||
JNIEnv* jni,
|
|
||||||
jclass,
|
|
||||||
jint nativeSeverity) {
|
|
||||||
if (nativeSeverity >= rtc::LS_SENSITIVE && nativeSeverity <= rtc::LS_NONE) {
|
|
||||||
rtc::LogMessage::LogToDebug(
|
|
||||||
static_cast<rtc::LoggingSeverity>(nativeSeverity));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
JNI_FUNCTION_DECLARATION(void,
|
JNI_FUNCTION_DECLARATION(void,
|
||||||
Logging_nativeEnableLogThreads,
|
Logging_nativeEnableLogThreads,
|
||||||
JNIEnv* jni,
|
JNIEnv* jni,
|
||||||
@ -42,18 +31,5 @@ JNI_FUNCTION_DECLARATION(void,
|
|||||||
rtc::LogMessage::LogTimestamps(true);
|
rtc::LogMessage::LogTimestamps(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNI_FUNCTION_DECLARATION(void,
|
|
||||||
Logging_nativeLog,
|
|
||||||
JNIEnv* jni,
|
|
||||||
jclass,
|
|
||||||
jint j_severity,
|
|
||||||
jstring j_tag,
|
|
||||||
jstring j_message) {
|
|
||||||
std::string message = JavaToStdString(jni, JavaParamRef<jstring>(j_message));
|
|
||||||
std::string tag = JavaToStdString(jni, JavaParamRef<jstring>(j_tag));
|
|
||||||
RTC_LOG_TAG(static_cast<rtc::LoggingSeverity>(j_severity), tag.c_str())
|
|
||||||
<< message;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace jni
|
} // namespace jni
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
46
sdk/android/src/jni/pc/native_logger.cc
Normal file
46
sdk/android/src/jni/pc/native_logger.cc
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Use of this source code is governed by a BSD-style license
|
||||||
|
* that can be found in the LICENSE file in the root of the source
|
||||||
|
* tree. An additional intellectual property rights grant can be found
|
||||||
|
* in the file PATENTS. All contributing project authors may
|
||||||
|
* be found in the AUTHORS file in the root of the source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
#include "rtc_base/logging.h"
|
||||||
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
|
||||||
|
namespace webrtc {
|
||||||
|
namespace jni {
|
||||||
|
|
||||||
|
JNI_FUNCTION_DECLARATION(void,
|
||||||
|
NativeLogger_nativeEnableLogToDebugOutput,
|
||||||
|
JNIEnv* jni,
|
||||||
|
jclass,
|
||||||
|
jint native_severity) {
|
||||||
|
// Check that native_severity is a valid enum.
|
||||||
|
if (native_severity >= rtc::LS_SENSITIVE && native_severity <= rtc::LS_NONE) {
|
||||||
|
rtc::LogMessage::LogToDebug(
|
||||||
|
static_cast<rtc::LoggingSeverity>(native_severity));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JNI_FUNCTION_DECLARATION(void,
|
||||||
|
NativeLogger_nativeLog,
|
||||||
|
JNIEnv* jni,
|
||||||
|
jclass,
|
||||||
|
jint j_severity,
|
||||||
|
jstring j_tag,
|
||||||
|
jstring j_message) {
|
||||||
|
std::string message = JavaToStdString(jni, JavaParamRef<jstring>(j_message));
|
||||||
|
std::string tag = JavaToStdString(jni, JavaParamRef<jstring>(j_tag));
|
||||||
|
RTC_LOG_TAG(static_cast<rtc::LoggingSeverity>(j_severity), tag.c_str())
|
||||||
|
<< message;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace jni
|
||||||
|
} // namespace webrtc
|
||||||
@ -27,6 +27,7 @@
|
|||||||
#include "sdk/android/generated_peerconnection_jni/jni/PeerConnectionFactory_jni.h"
|
#include "sdk/android/generated_peerconnection_jni/jni/PeerConnectionFactory_jni.h"
|
||||||
#include "sdk/android/native_api/jni/java_types.h"
|
#include "sdk/android/native_api/jni/java_types.h"
|
||||||
#include "sdk/android/src/jni/jni_helpers.h"
|
#include "sdk/android/src/jni/jni_helpers.h"
|
||||||
|
#include "sdk/android/src/jni/logging/logsink.h"
|
||||||
#include "sdk/android/src/jni/pc/androidnetworkmonitor.h"
|
#include "sdk/android/src/jni/pc/androidnetworkmonitor.h"
|
||||||
#include "sdk/android/src/jni/pc/audio.h"
|
#include "sdk/android/src/jni/pc/audio.h"
|
||||||
#include "sdk/android/src/jni/pc/icecandidate.h"
|
#include "sdk/android/src/jni/pc/icecandidate.h"
|
||||||
@ -81,6 +82,9 @@ static char* field_trials_init_string = nullptr;
|
|||||||
static bool factory_static_initialized = false;
|
static bool factory_static_initialized = false;
|
||||||
static bool video_hw_acceleration_enabled = true;
|
static bool video_hw_acceleration_enabled = true;
|
||||||
|
|
||||||
|
// Set in PeerConnectionFactory_InjectLoggable().
|
||||||
|
static std::unique_ptr<JNILogSink> jni_log_sink;
|
||||||
|
|
||||||
void PeerConnectionFactoryNetworkThreadReady() {
|
void PeerConnectionFactoryNetworkThreadReady() {
|
||||||
RTC_LOG(LS_INFO) << "Network thread JavaCallback";
|
RTC_LOG(LS_INFO) << "Network thread JavaCallback";
|
||||||
JNIEnv* env = AttachCurrentThreadIfNeeded();
|
JNIEnv* env = AttachCurrentThreadIfNeeded();
|
||||||
@ -503,5 +507,29 @@ static jlong JNI_PeerConnectionFactory_GetNativePeerConnectionFactory(
|
|||||||
return jlongFromPointer(factoryFromJava(native_factory));
|
return jlongFromPointer(factoryFromJava(native_factory));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void JNI_PeerConnectionFactory_InjectLoggable(
|
||||||
|
JNIEnv* jni,
|
||||||
|
const JavaParamRef<jclass>&,
|
||||||
|
const JavaParamRef<jobject>& j_logging,
|
||||||
|
jint nativeSeverity) {
|
||||||
|
// If there is already a LogSink, remove it from LogMessage.
|
||||||
|
if (jni_log_sink) {
|
||||||
|
rtc::LogMessage::RemoveLogToStream(jni_log_sink.get());
|
||||||
|
}
|
||||||
|
jni_log_sink = rtc::MakeUnique<JNILogSink>(jni, j_logging);
|
||||||
|
rtc::LogMessage::AddLogToStream(
|
||||||
|
jni_log_sink.get(), static_cast<rtc::LoggingSeverity>(nativeSeverity));
|
||||||
|
rtc::LogMessage::LogToDebug(rtc::LS_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void JNI_PeerConnectionFactory_DeleteLoggable(
|
||||||
|
JNIEnv* jni,
|
||||||
|
const JavaParamRef<jclass>&) {
|
||||||
|
if (jni_log_sink) {
|
||||||
|
rtc::LogMessage::RemoveLogToStream(jni_log_sink.get());
|
||||||
|
jni_log_sink.reset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace jni
|
} // namespace jni
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|||||||
Reference in New Issue
Block a user