davidliu
Committed by GitHub

Logging for WebRTC library (#75)

... ... @@ -12,6 +12,12 @@ import timber.log.Timber
class LiveKit {
companion object {
/**
* [LoggingLevel] to use for Livekit logs. Set to [LoggingLevel.OFF] to turn off logs.
*
* Defaults to [LoggingLevel.OFF]
*/
@JvmStatic
var loggingLevel: LoggingLevel
get() = LKLog.loggingLevel
set(value) {
... ... @@ -28,6 +34,14 @@ class LiveKit {
}
}
/**
* Enables logs for the underlying WebRTC sdk logging. Used in conjunction with [loggingLevel].
*
* Note: WebRTC logging is very noisy and should only be used to diagnose native WebRTC issues.
*/
@JvmStatic
var enableWebRTCLogging: Boolean = false
fun create(
appContext: Context,
options: RoomOptions = RoomOptions(),
... ...
... ... @@ -4,11 +4,14 @@ import android.content.Context
import androidx.annotation.Nullable
import dagger.Module
import dagger.Provides
import io.livekit.android.LiveKit
import io.livekit.android.util.LKLog
import io.livekit.android.util.LoggingLevel
import io.livekit.android.webrtc.SimulcastVideoEncoderFactoryWrapper
import org.webrtc.*
import org.webrtc.audio.AudioDeviceModule
import org.webrtc.audio.JavaAudioDeviceModule
import timber.log.Timber
import javax.inject.Named
import javax.inject.Singleton
... ... @@ -140,9 +143,25 @@ object RTCModule {
PeerConnectionFactory.initialize(
PeerConnectionFactory.InitializationOptions
.builder(appContext)
.setInjectableLogger({ s, severity, s2 ->
if (!LiveKit.enableWebRTCLogging) {
return@setInjectableLogger
}
val loggingLevel = when (severity) {
Logging.Severity.LS_VERBOSE -> LoggingLevel.VERBOSE
Logging.Severity.LS_INFO -> LoggingLevel.INFO
Logging.Severity.LS_WARNING -> LoggingLevel.WARN
Logging.Severity.LS_ERROR -> LoggingLevel.ERROR
else -> LoggingLevel.OFF
}
LKLog.log(loggingLevel) {
Timber.log(loggingLevel.toAndroidLogPriority(), "$s2: $s")
}
}, Logging.Severity.LS_VERBOSE)
.createInitializationOptions()
)
return PeerConnectionFactory.builder()
.setAudioDeviceModule(audioDeviceModule)
.setVideoEncoderFactory(videoEncoderFactory)
... ...
package io.livekit.android.util
import android.util.Log
enum class LoggingLevel {
VERBOSE,
INFO,
... ... @@ -6,5 +9,18 @@ enum class LoggingLevel {
WARN,
ERROR,
WTF,
OFF,
}
\ No newline at end of file
OFF;
fun toAndroidLogPriority(): Int {
return when (this) {
VERBOSE -> Log.VERBOSE
INFO -> Log.INFO
DEBUG -> Log.DEBUG
WARN -> Log.WARN
ERROR -> Log.ERROR
WTF -> Log.ERROR
OFF -> 0
}
}
}
... ...