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:
Paulina Hensman
2018-05-15 13:41:06 +02:00
committed by Commit Bot
parent 8694f29b30
commit 59216ec4a4
16 changed files with 390 additions and 70 deletions

View File

@ -13,6 +13,7 @@ package org.webrtc;
import android.content.Context;
import java.util.List;
import javax.annotation.Nullable;
import org.webrtc.Logging.Severity;
import org.webrtc.audio.AudioDeviceModule;
import org.webrtc.audio.LegacyAudioDeviceModule;
@ -42,15 +43,20 @@ public class PeerConnectionFactory {
final boolean enableInternalTracer;
final boolean enableVideoHwAcceleration;
final NativeLibraryLoader nativeLibraryLoader;
@Nullable Loggable loggable;
@Nullable Severity loggableSeverity;
private InitializationOptions(Context applicationContext, String fieldTrials,
boolean enableInternalTracer, boolean enableVideoHwAcceleration,
NativeLibraryLoader nativeLibraryLoader) {
NativeLibraryLoader nativeLibraryLoader, @Nullable Loggable loggable,
@Nullable Severity loggableSeverity) {
this.applicationContext = applicationContext;
this.fieldTrials = fieldTrials;
this.enableInternalTracer = enableInternalTracer;
this.enableVideoHwAcceleration = enableVideoHwAcceleration;
this.nativeLibraryLoader = nativeLibraryLoader;
this.loggable = loggable;
this.loggableSeverity = loggableSeverity;
}
public static Builder builder(Context applicationContext) {
@ -63,6 +69,8 @@ public class PeerConnectionFactory {
private boolean enableInternalTracer = false;
private boolean enableVideoHwAcceleration = true;
private NativeLibraryLoader nativeLibraryLoader = new NativeLibrary.DefaultLoader();
@Nullable private Loggable loggable = null;
@Nullable private Severity loggableSeverity = null;
Builder(Context applicationContext) {
this.applicationContext = applicationContext;
@ -88,9 +96,16 @@ public class PeerConnectionFactory {
return this;
}
public Builder setInjectableLogger(Loggable loggable, Severity severity) {
this.loggable = loggable;
this.loggableSeverity = severity;
return this;
}
public PeerConnectionFactory.InitializationOptions createInitializationOptions() {
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) {
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() {
@ -475,4 +497,6 @@ public class PeerConnectionFactory {
private static native void nativeInvokeThreadsCallbacks(long factory);
private static native void nativeFreeFactory(long factory);
private static native long nativeGetNativePeerConnectionFactory(long factory);
private static native void nativeInjectLoggable(JNILogging jniLogging, int severity);
private static native void nativeDeleteLoggable();
}