summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorHarsh Shandilya <me@msfjarvis.dev>2022-10-24 15:29:32 +0530
committerHarsh Shandilya <me@msfjarvis.dev>2022-10-24 15:46:26 +0530
commit2762c1757848efcb789b58e819987633a59ba270 (patch)
tree1daeaf55c4241f25ad69389259959e860dc9c480 /app/src/main/java
parent816aca5ba18446f2d14cb993d47c6119a548135b (diff)
feat: setup Beagle for debugging
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/app/passwordstore/Application.kt41
-rw-r--r--app/src/main/java/app/passwordstore/util/log/ForwardingLogcatLogger.kt24
2 files changed, 63 insertions, 2 deletions
diff --git a/app/src/main/java/app/passwordstore/Application.kt b/app/src/main/java/app/passwordstore/Application.kt
index fb4c0f63..4737c088 100644
--- a/app/src/main/java/app/passwordstore/Application.kt
+++ b/app/src/main/java/app/passwordstore/Application.kt
@@ -18,17 +18,28 @@ import app.passwordstore.util.extensions.getString
import app.passwordstore.util.features.Feature
import app.passwordstore.util.features.Features
import app.passwordstore.util.git.sshj.setUpBouncyCastleForSshj
+import app.passwordstore.util.log.ForwardingLogcatLogger
import app.passwordstore.util.proxy.ProxyUtils
import app.passwordstore.util.settings.GitSettings
import app.passwordstore.util.settings.PreferenceKeys
import app.passwordstore.util.settings.runMigrations
import com.google.android.material.color.DynamicColors
+import com.pandulapeter.beagle.Beagle
+import com.pandulapeter.beagle.common.configuration.Behavior
+import com.pandulapeter.beagle.log.BeagleLogger
+import com.pandulapeter.beagle.modules.AppInfoButtonModule
+import com.pandulapeter.beagle.modules.DeviceInfoModule
+import com.pandulapeter.beagle.modules.DividerModule
+import com.pandulapeter.beagle.modules.HeaderModule
+import com.pandulapeter.beagle.modules.LifecycleLogListModule
+import com.pandulapeter.beagle.modules.LogListModule
+import com.pandulapeter.beagle.modules.PaddingModule
+import com.pandulapeter.beagle.modules.ScreenCaptureToolboxModule
import dagger.hilt.android.HiltAndroidApp
import io.sentry.Sentry
import io.sentry.protocol.User
import java.util.concurrent.Executors
import javax.inject.Inject
-import logcat.AndroidLogcatLogger
import logcat.LogPriority.DEBUG
import logcat.LogPriority.VERBOSE
import logcat.LogcatLogger
@@ -51,7 +62,33 @@ class Application : android.app.Application(), SharedPreferences.OnSharedPrefere
BuildConfig.ENABLE_DEBUG_FEATURES ||
prefs.getBoolean(PreferenceKeys.ENABLE_DEBUG_LOGGING, false)
) {
- LogcatLogger.install(AndroidLogcatLogger(DEBUG))
+ Beagle.initialize(
+ application = this,
+ behavior =
+ Behavior(
+ logBehavior =
+ Behavior.LogBehavior(
+ loggers = listOf(BeagleLogger),
+ )
+ )
+ )
+ Beagle.set(
+ HeaderModule(
+ title = getString(R.string.app_name),
+ subtitle = BuildConfig.APPLICATION_ID,
+ text =
+ "${BuildConfig.BUILD_TYPE} v${BuildConfig.VERSION_NAME} (${BuildConfig.VERSION_CODE})"
+ ),
+ AppInfoButtonModule(),
+ PaddingModule(),
+ ScreenCaptureToolboxModule(),
+ DividerModule(),
+ LogListModule(),
+ LifecycleLogListModule(),
+ DividerModule(),
+ DeviceInfoModule(),
+ )
+ LogcatLogger.install(ForwardingLogcatLogger(DEBUG))
setVmPolicy()
}
prefs.registerOnSharedPreferenceChangeListener(this)
diff --git a/app/src/main/java/app/passwordstore/util/log/ForwardingLogcatLogger.kt b/app/src/main/java/app/passwordstore/util/log/ForwardingLogcatLogger.kt
new file mode 100644
index 00000000..15b2a0c7
--- /dev/null
+++ b/app/src/main/java/app/passwordstore/util/log/ForwardingLogcatLogger.kt
@@ -0,0 +1,24 @@
+package app.passwordstore.util.log
+
+import com.pandulapeter.beagle.log.BeagleLogger
+import logcat.AndroidLogcatLogger
+import logcat.LogPriority
+import logcat.LogPriority.DEBUG
+import logcat.LogcatLogger
+
+/**
+ * Wrapper around [AndroidLogcatLogger] that ensures all logged messages are also forwarded to
+ * [BeagleLogger].
+ */
+class ForwardingLogcatLogger(minPriority: LogPriority = DEBUG) : LogcatLogger {
+ private val androidLogger = AndroidLogcatLogger(minPriority)
+
+ override fun isLoggable(priority: LogPriority): Boolean {
+ return androidLogger.isLoggable(priority)
+ }
+
+ override fun log(priority: LogPriority, tag: String, message: String) {
+ androidLogger.log(priority, tag, message)
+ BeagleLogger.log(message = "[$tag]: $message", label = "Logcat", isPersisted = true)
+ }
+}