正在显示
3 个修改的文件
包含
52 行增加
和
3 行删除
| @@ -12,6 +12,12 @@ import timber.log.Timber | @@ -12,6 +12,12 @@ import timber.log.Timber | ||
| 12 | 12 | ||
| 13 | class LiveKit { | 13 | class LiveKit { |
| 14 | companion object { | 14 | companion object { |
| 15 | + /** | ||
| 16 | + * [LoggingLevel] to use for Livekit logs. Set to [LoggingLevel.OFF] to turn off logs. | ||
| 17 | + * | ||
| 18 | + * Defaults to [LoggingLevel.OFF] | ||
| 19 | + */ | ||
| 20 | + @JvmStatic | ||
| 15 | var loggingLevel: LoggingLevel | 21 | var loggingLevel: LoggingLevel |
| 16 | get() = LKLog.loggingLevel | 22 | get() = LKLog.loggingLevel |
| 17 | set(value) { | 23 | set(value) { |
| @@ -28,6 +34,14 @@ class LiveKit { | @@ -28,6 +34,14 @@ class LiveKit { | ||
| 28 | } | 34 | } |
| 29 | } | 35 | } |
| 30 | 36 | ||
| 37 | + /** | ||
| 38 | + * Enables logs for the underlying WebRTC sdk logging. Used in conjunction with [loggingLevel]. | ||
| 39 | + * | ||
| 40 | + * Note: WebRTC logging is very noisy and should only be used to diagnose native WebRTC issues. | ||
| 41 | + */ | ||
| 42 | + @JvmStatic | ||
| 43 | + var enableWebRTCLogging: Boolean = false | ||
| 44 | + | ||
| 31 | fun create( | 45 | fun create( |
| 32 | appContext: Context, | 46 | appContext: Context, |
| 33 | options: RoomOptions = RoomOptions(), | 47 | options: RoomOptions = RoomOptions(), |
| @@ -4,11 +4,14 @@ import android.content.Context | @@ -4,11 +4,14 @@ import android.content.Context | ||
| 4 | import androidx.annotation.Nullable | 4 | import androidx.annotation.Nullable |
| 5 | import dagger.Module | 5 | import dagger.Module |
| 6 | import dagger.Provides | 6 | import dagger.Provides |
| 7 | +import io.livekit.android.LiveKit | ||
| 7 | import io.livekit.android.util.LKLog | 8 | import io.livekit.android.util.LKLog |
| 9 | +import io.livekit.android.util.LoggingLevel | ||
| 8 | import io.livekit.android.webrtc.SimulcastVideoEncoderFactoryWrapper | 10 | import io.livekit.android.webrtc.SimulcastVideoEncoderFactoryWrapper |
| 9 | import org.webrtc.* | 11 | import org.webrtc.* |
| 10 | import org.webrtc.audio.AudioDeviceModule | 12 | import org.webrtc.audio.AudioDeviceModule |
| 11 | import org.webrtc.audio.JavaAudioDeviceModule | 13 | import org.webrtc.audio.JavaAudioDeviceModule |
| 14 | +import timber.log.Timber | ||
| 12 | import javax.inject.Named | 15 | import javax.inject.Named |
| 13 | import javax.inject.Singleton | 16 | import javax.inject.Singleton |
| 14 | 17 | ||
| @@ -140,9 +143,25 @@ object RTCModule { | @@ -140,9 +143,25 @@ object RTCModule { | ||
| 140 | PeerConnectionFactory.initialize( | 143 | PeerConnectionFactory.initialize( |
| 141 | PeerConnectionFactory.InitializationOptions | 144 | PeerConnectionFactory.InitializationOptions |
| 142 | .builder(appContext) | 145 | .builder(appContext) |
| 146 | + .setInjectableLogger({ s, severity, s2 -> | ||
| 147 | + if (!LiveKit.enableWebRTCLogging) { | ||
| 148 | + return@setInjectableLogger | ||
| 149 | + } | ||
| 150 | + | ||
| 151 | + val loggingLevel = when (severity) { | ||
| 152 | + Logging.Severity.LS_VERBOSE -> LoggingLevel.VERBOSE | ||
| 153 | + Logging.Severity.LS_INFO -> LoggingLevel.INFO | ||
| 154 | + Logging.Severity.LS_WARNING -> LoggingLevel.WARN | ||
| 155 | + Logging.Severity.LS_ERROR -> LoggingLevel.ERROR | ||
| 156 | + else -> LoggingLevel.OFF | ||
| 157 | + } | ||
| 158 | + | ||
| 159 | + LKLog.log(loggingLevel) { | ||
| 160 | + Timber.log(loggingLevel.toAndroidLogPriority(), "$s2: $s") | ||
| 161 | + } | ||
| 162 | + }, Logging.Severity.LS_VERBOSE) | ||
| 143 | .createInitializationOptions() | 163 | .createInitializationOptions() |
| 144 | ) | 164 | ) |
| 145 | - | ||
| 146 | return PeerConnectionFactory.builder() | 165 | return PeerConnectionFactory.builder() |
| 147 | .setAudioDeviceModule(audioDeviceModule) | 166 | .setAudioDeviceModule(audioDeviceModule) |
| 148 | .setVideoEncoderFactory(videoEncoderFactory) | 167 | .setVideoEncoderFactory(videoEncoderFactory) |
| 1 | package io.livekit.android.util | 1 | package io.livekit.android.util |
| 2 | + | ||
| 3 | +import android.util.Log | ||
| 4 | + | ||
| 2 | enum class LoggingLevel { | 5 | enum class LoggingLevel { |
| 3 | VERBOSE, | 6 | VERBOSE, |
| 4 | INFO, | 7 | INFO, |
| @@ -6,5 +9,18 @@ enum class LoggingLevel { | @@ -6,5 +9,18 @@ enum class LoggingLevel { | ||
| 6 | WARN, | 9 | WARN, |
| 7 | ERROR, | 10 | ERROR, |
| 8 | WTF, | 11 | WTF, |
| 9 | - OFF, | ||
| 10 | -} | ||
| 12 | + OFF; | ||
| 13 | + | ||
| 14 | + fun toAndroidLogPriority(): Int { | ||
| 15 | + return when (this) { | ||
| 16 | + VERBOSE -> Log.VERBOSE | ||
| 17 | + INFO -> Log.INFO | ||
| 18 | + DEBUG -> Log.DEBUG | ||
| 19 | + WARN -> Log.WARN | ||
| 20 | + ERROR -> Log.ERROR | ||
| 21 | + WTF -> Log.ERROR | ||
| 22 | + OFF -> 0 | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | +} | ||
| 26 | + |
-
请 注册 或 登录 后发表评论