Use new APIs for debug logs

This commit is contained in:
Sylvain Berfini 2021-06-21 10:25:58 +02:00
parent 49fb77f0be
commit 7e6530504a
4 changed files with 26 additions and 14 deletions

View file

@ -22,10 +22,7 @@ package org.linphone
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.app.Application import android.app.Application
import android.content.Context import android.content.Context
import org.linphone.core.CoreContext import org.linphone.core.*
import org.linphone.core.CorePreferences
import org.linphone.core.Factory
import org.linphone.core.LogCollectionState
import org.linphone.core.tools.Log import org.linphone.core.tools.Log
class LinphoneApplication : Application() { class LinphoneApplication : Application() {
@ -55,7 +52,11 @@ class LinphoneApplication : Application() {
corePreferences.config = config corePreferences.config = config
val appName = context.getString(R.string.app_name) val appName = context.getString(R.string.app_name)
Factory.instance().setDebugMode(corePreferences.debugLogs, appName) Factory.instance().setLoggerDomain(appName)
Factory.instance().enableLogcatLogs(corePreferences.logcatLogsOutput)
if (corePreferences.debugLogs) {
Factory.instance().loggingService.setLogLevel(LogLevel.Message)
}
Log.i("[Application] Core context created ${if (pushReceived) "from push" else ""}") Log.i("[Application] Core context created ${if (pushReceived) "from push" else ""}")
coreContext = CoreContext(context, config) coreContext = CoreContext(context, config)

View file

@ -27,8 +27,8 @@ import org.linphone.activities.main.settings.SettingListenerStub
import org.linphone.activities.main.viewmodels.LogsUploadViewModel import org.linphone.activities.main.viewmodels.LogsUploadViewModel
import org.linphone.core.CoreContext import org.linphone.core.CoreContext
import org.linphone.core.Factory import org.linphone.core.Factory
import org.linphone.core.LogLevel
import org.linphone.mediastream.Version import org.linphone.mediastream.Version
import org.linphone.utils.AppUtils
import org.linphone.utils.Event import org.linphone.utils.Event
class AdvancedSettingsViewModel : LogsUploadViewModel() { class AdvancedSettingsViewModel : LogsUploadViewModel() {
@ -38,8 +38,8 @@ class AdvancedSettingsViewModel : LogsUploadViewModel() {
val debugModeListener = object : SettingListenerStub() { val debugModeListener = object : SettingListenerStub() {
override fun onBoolValueChanged(newValue: Boolean) { override fun onBoolValueChanged(newValue: Boolean) {
prefs.debugLogs = newValue prefs.debugLogs = newValue
val appName = AppUtils.getString(R.string.app_name) val logLevel = if (newValue) LogLevel.Message else LogLevel.Error
Factory.instance().setDebugMode(prefs.debugLogs, appName) Factory.instance().loggingService.setLogLevel(logLevel)
} }
} }
val debugMode = MutableLiveData<Boolean>() val debugMode = MutableLiveData<Boolean>()

View file

@ -266,6 +266,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
level: LogLevel, level: LogLevel,
message: String message: String
) { ) {
if (corePreferences.logcatLogsOutput) {
when (level) { when (level) {
LogLevel.Error -> android.util.Log.e(domain, message) LogLevel.Error -> android.util.Log.e(domain, message)
LogLevel.Warning -> android.util.Log.w(domain, message) LogLevel.Warning -> android.util.Log.w(domain, message)
@ -273,6 +274,7 @@ class CoreContext(val context: Context, coreConfig: Config) {
LogLevel.Fatal -> android.util.Log.wtf(domain, message) LogLevel.Fatal -> android.util.Log.wtf(domain, message)
else -> android.util.Log.d(domain, message) else -> android.util.Log.d(domain, message)
} }
}
FirebaseCrashlytics.getInstance().log("[$domain] [${level.name}] $message") FirebaseCrashlytics.getInstance().log("[$domain] [${level.name}] $message")
} }
} }

View file

@ -64,6 +64,9 @@ class CorePreferences constructor(private val context: Context) {
return return
} }
encryptedSharedPreferences.edit().putBoolean("vfs_enabled", value).apply() encryptedSharedPreferences.edit().putBoolean("vfs_enabled", value).apply()
// When VFS is enabled we disable logcat output for linphone logs
// TODO: decide if we do it
// logcatLogsOutput = false
} }
/* App settings */ /* App settings */
@ -74,6 +77,12 @@ class CorePreferences constructor(private val context: Context) {
config.setBool("app", "debug", value) config.setBool("app", "debug", value)
} }
var logcatLogsOutput: Boolean
get() = config.getBool("app", "print_logs_into_logcat", true)
set(value) {
config.setBool("app", "print_logs_into_logcat", value)
}
var autoStart: Boolean var autoStart: Boolean
get() = config.getBool("app", "auto_start", true) get() = config.getBool("app", "auto_start", true)
set(value) { set(value) {