in support of #212 log messages before analytics enabled

pull/214/head
Kevin Hester 2021-01-05 12:01:42 +08:00
rodzic 2dd2a9ddbb
commit 43999e3d72
2 zmienionych plików z 20 dodań i 12 usunięć

Wyświetl plik

@ -27,20 +27,27 @@ class MeshUtilApplication : GeeksvilleApplication() {
val pref = AppPrefs(this)
crashlytics.setUserId(pref.getInstallId()) // be able to group all bugs per anonymous user
// We always send our log messages to the crashlytics lib, but they only get sent to the server if we report an exception
// This makes log messages work properly if someone turns on analytics just before they click report bug.
// send all log messages through crashyltics, so if we do crash we'll have those in the report
val standardLogger = Logging.printlog
Logging.printlog = { level, tag, message ->
crashlytics.log("$tag: $message")
standardLogger(level, tag, message)
}
fun sendCrashReports() {
if(isAnalyticsAllowed)
crashlytics.sendUnsentReports()
}
// Send any old reports if user approves
sendCrashReports()
// Attach to our exception wrapper
Exceptions.reporter = { exception, _, _ ->
crashlytics.recordException(exception)
crashlytics.sendUnsentReports()
}
if (isAnalyticsAllowed) {
val standardLogger = Logging.printlog
// send all log messages through crashyltics, so if we do crash we'll have those in the report
Logging.printlog = { level, tag, message ->
crashlytics.log("$tag: $message")
standardLogger(level, tag, message)
}
sendCrashReports() // Send the new report
}
}

Wyświetl plik

@ -8,6 +8,7 @@ import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.Worker
import androidx.work.WorkerParameters
import com.geeksville.andlib.BuildConfig
import java.util.concurrent.TimeUnit
/**
@ -65,6 +66,6 @@ fun MeshService.Companion.startService(context: Context) {
// Before binding we want to explicitly create - so the service stays alive forever (so it can keep
// listening for the bluetooth packets arriving from the radio. And when they arrive forward them
// to Signal or whatever.
info("Trying to start service")
info("Trying to start service debug=${BuildConfig.DEBUG}")
requireNotNull(context.startMeshService()) { "Failed to start service" }
}