Skip to content

Commit 50876b8

Browse files
committed
chore: allow enabling traces (to std out) on production builds
Signed-off-by: Brandon McAnsh <[email protected]>
1 parent de5b5ca commit 50876b8

File tree

6 files changed

+51
-1
lines changed

6 files changed

+51
-1
lines changed

apps/flipcash/features/appupdates/src/main/kotlin/com/flipcash/app/updates/LocalAppUpdater.kt renamed to apps/flipcash/shared/appupdates/src/main/kotlin/com/flipcash/app/updates/LocalAppUpdater.kt

File renamed without changes.

apps/flipcash/shared/authentication/src/main/kotlin/com/flipcash/app/auth/AuthManager.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import com.flipcash.services.user.AuthState
1414
import com.flipcash.services.user.UserManager
1515
import com.flipcash.shared.authentication.BuildConfig
1616
import com.getcode.crypt.MnemonicPhrase
17-
import com.getcode.opencode.controllers.BalanceController
1817
import com.getcode.opencode.controllers.TokenController
1918
import com.getcode.opencode.model.core.ID
2019
import com.getcode.utils.TraceType

apps/flipcash/shared/featureflags/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ dependencies {
4545
implementation(project(":apps:flipcash:shared:ksp"))
4646
ksp(project(":apps:flipcash:shared:ksp"))
4747

48+
implementation(project(":libs:logging"))
49+
50+
4851
implementation(platform(Libs.firebase_bom))
4952
implementation(Libs.firebase_messaging)
5053
implementation(Libs.bugsnag)

apps/flipcash/shared/featureflags/src/main/kotlin/com/flipcash/app/featureflags/FeatureFlag.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.flipcash.app.featureflags
22

33
import com.flipcash.app.ksp.annotations.FeatureFlagMarker
4+
import com.flipcash.shared.flags.BuildConfig
45

56
sealed interface FeatureFlag {
67
val key: String
@@ -72,6 +73,15 @@ sealed interface FeatureFlag {
7273
override val persistLogOut: Boolean = false
7374
}
7475

76+
@FeatureFlagMarker
77+
data object ProductionLogging: FeatureFlag {
78+
override val key: String = "production_logging_enabled"
79+
override val default: Boolean = false
80+
override val launched: Boolean = false
81+
override val visible: Boolean = !BuildConfig.DEBUG
82+
override val persistLogOut: Boolean = true
83+
}
84+
7585
companion object {
7686
val entries: List<FeatureFlag>
7787
get() = FeatureFlagEntries.entries
@@ -92,6 +102,7 @@ val FeatureFlag.title: String
92102
FeatureFlag.Pools -> "Betting Pools"
93103
FeatureFlag.OnRamp -> "Onramp"
94104
FeatureFlag.BillCustomizer -> "Bill Customizer"
105+
FeatureFlag.ProductionLogging -> "Production Logging"
95106
}
96107

97108
val FeatureFlag.message: String
@@ -103,6 +114,7 @@ val FeatureFlag.message: String
103114
FeatureFlag.Pools -> "When enabled, you'll be able to participate in and create betting pools with other users for a chance to win a share of the prize"
104115
FeatureFlag.OnRamp -> "When enabled, you'll gain the ability to fund your wallet from external sources via providers using a debit card or via another wallet (like Phantom)"
105116
FeatureFlag.BillCustomizer -> "When enabled, you'll gain access to the bill customization playground"
117+
FeatureFlag.ProductionLogging -> "When enabled, traces will print to log output"
106118
}
107119

108120

apps/flipcash/shared/featureflags/src/main/kotlin/com/flipcash/app/featureflags/internal/InternalFeatureFlagController.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ import androidx.datastore.preferences.preferencesDataStoreFile
1010
import com.flipcash.app.featureflags.BetaFeature
1111
import com.flipcash.app.featureflags.FeatureFlag
1212
import com.flipcash.app.featureflags.FeatureFlagController
13+
import com.getcode.utils.TraceManager
1314
import dagger.hilt.android.qualifiers.ApplicationContext
1415
import kotlinx.coroutines.CoroutineScope
1516
import kotlinx.coroutines.Dispatchers
1617
import kotlinx.coroutines.SupervisorJob
1718
import kotlinx.coroutines.flow.SharingStarted
1819
import kotlinx.coroutines.flow.StateFlow
1920
import kotlinx.coroutines.flow.firstOrNull
21+
import kotlinx.coroutines.flow.launchIn
2022
import kotlinx.coroutines.flow.map
23+
import kotlinx.coroutines.flow.onEach
2124
import kotlinx.coroutines.flow.stateIn
2225
import kotlinx.coroutines.launch
2326
import javax.inject.Inject
@@ -48,6 +51,10 @@ internal class InternalFeatureFlagController @Inject constructor(
4851
FeatureFlag.entries
4952
.filter { it.launched }
5053
.onEach { reset(it) }
54+
55+
observe(FeatureFlag.ProductionLogging)
56+
.onEach { TraceManager.enableProductionTraces(it) }
57+
.launchIn(dataScope)
5158
}
5259

5360
override fun enableBetaFeatures() {

libs/logging/src/main/kotlin/com/getcode/utils/Logging.kt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.getcode.utils
33
import android.annotation.SuppressLint
44
import com.bugsnag.android.BreadcrumbType
55
import com.bugsnag.android.Bugsnag
6+
import com.getcode.libs.logging.BuildConfig
67
import com.google.firebase.crashlytics.CustomKeysAndValues
78
import com.google.firebase.crashlytics.FirebaseCrashlytics
89
import timber.log.Timber
@@ -66,6 +67,34 @@ private fun TraceType.toBugsnagBreadcrumbType(): BreadcrumbType? {
6667
}
6768
}
6869

70+
object TraceManager {
71+
private val productionTraceTree = object: Timber.Tree() {
72+
override fun log(
73+
priority: Int,
74+
tag: String?,
75+
message: String,
76+
t: Throwable?
77+
) {
78+
println("[TRACE] $tag $message")
79+
t?.printStackTrace()
80+
}
81+
82+
}
83+
fun enableProductionTraces(enable: Boolean) {
84+
if (!BuildConfig.DEBUG) {
85+
if (enable) {
86+
if (!Timber.forest().contains(productionTraceTree)) {
87+
Timber.plant(productionTraceTree)
88+
}
89+
} else {
90+
if (Timber.forest().contains(productionTraceTree)) {
91+
Timber.uproot(productionTraceTree)
92+
}
93+
}
94+
}
95+
}
96+
}
97+
6998
@SuppressLint("TimberExceptionLogging")
7099
fun trace(
71100
message: String,

0 commit comments

Comments
 (0)