Skip to content

Commit

Permalink
Move from timber to Logger
Browse files Browse the repository at this point in the history
  • Loading branch information
simond-stripe committed Oct 16, 2024
1 parent 3db4ef5 commit 9372621
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 34 deletions.
2 changes: 0 additions & 2 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ ext.versions = [
tensorflowLite : '2.11.0',
tensorflowLiteSupport : '0.4.3',
testParameterInjector : '1.17',
timber : '5.0.1',
truth : '1.4.4',
turbine : '1.1.0',
uiAutomator : '2.3.0',
Expand Down Expand Up @@ -191,7 +190,6 @@ ext.libs = [
tensorflowLiteSupport : "org.tensorflow:tensorflow-lite-support:${versions.tensorflowLiteSupport}",
tensorflowLitePlayServices : "com.google.android.gms:play-services-tflite-java:${versions.playServicesTfLite}",
tensorflowLitePlayServicesSupport : "com.google.android.gms:play-services-tflite-support:${versions.playServicesTfLite}",
timber : "com.jakewharton.timber:timber:${versions.timber}",
zxing : "com.google.zxing:core:${versions.zxing}",
]

Expand Down
3 changes: 0 additions & 3 deletions stripe-connect-example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ dependencies {
implementation libs.kotlin.coroutinesAndroid
implementation libs.kotlin.serialization

// Logging
implementation libs.timber

// Networking
implementation libs.fuel
implementation libs.fuelCoroutines
Expand Down
3 changes: 0 additions & 3 deletions stripe-connect-example/dependencies/dependencies.txt
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,6 @@
+--- org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3 (*)
+--- org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3 (*)
+--- org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2 (*)
+--- com.jakewharton.timber:timber:5.0.1
| +--- org.jetbrains.kotlin:kotlin-stdlib:1.5.21 -> 1.9.24 (*)
| \--- org.jetbrains:annotations:20.1.0 -> 23.0.0
+--- com.github.kittinunf.fuel:fuel:2.3.1
| +--- com.github.kittinunf.result:result:3.1.0
| | \--- org.jetbrains.kotlin:kotlin-stdlib:1.4.0 -> 1.9.24 (*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.stripe.android.connectsdk.example

import android.app.Application
import android.os.StrictMode
import timber.log.Timber

class App : Application() {
override fun onCreate() {
Expand All @@ -24,9 +23,5 @@ class App : Application() {
.penaltyLog()
.build()
)

if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.github.kittinunf.fuel.core.Request
import com.github.kittinunf.fuel.core.Response
import com.github.kittinunf.fuel.core.awaitResult
import com.github.kittinunf.result.Result
import com.stripe.android.core.Logger
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand All @@ -16,8 +17,8 @@ class EmbeddedComponentService {
private val fuel = FuelManager.instance
.apply {
// add logging
addRequestInterceptor(TimberRequestLogger("EmbeddedComponentService"))
addResponseInterceptor(TimberResponseLogger("EmbeddedComponentService"))
addRequestInterceptor(RequestLogger(tag = "EmbeddedComponentService"))
addResponseInterceptor(ResponseLogger(tag = "EmbeddedComponentService"))

// add headers
addRequestInterceptor(ApplicationJsonHeaderInterceptor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ import com.github.kittinunf.fuel.core.FoldableResponseInterceptor
import com.github.kittinunf.fuel.core.RequestTransformer
import com.github.kittinunf.fuel.core.ResponseTransformer
import com.github.kittinunf.fuel.core.extensions.cUrlString
import com.stripe.android.connectsdk.example.BuildConfig
import com.stripe.android.core.Logger
import com.stripe.android.core.version.StripeSdkVersion
import timber.log.Timber

object ApplicationJsonHeaderInterceptor : FoldableRequestInterceptor {
override fun invoke(next: RequestTransformer): RequestTransformer {
Expand Down Expand Up @@ -36,23 +37,25 @@ object UserAgentHeader : FoldableRequestInterceptor {
}
}

class TimberRequestLogger(private val tag: String) : FoldableRequestInterceptor {
private val timber get() = Timber.tag(tag)

class RequestLogger(
private val tag: String,
private val logger: Logger = Logger.getInstance(enableLogging = BuildConfig.DEBUG),
) : FoldableRequestInterceptor {
override fun invoke(next: RequestTransformer): RequestTransformer {
return { request ->
timber.i("Request: ${request.cUrlString()}")
logger.info("($tag) Request: ${request.cUrlString()}")
next(request)
}
}
}

class TimberResponseLogger(private val tag: String) : FoldableResponseInterceptor {
private val timber get() = Timber.tag(tag)

class ResponseLogger(
private val tag: String,
private val logger: Logger = Logger.getInstance(enableLogging = BuildConfig.DEBUG),
) : FoldableResponseInterceptor {
override fun invoke(next: ResponseTransformer): ResponseTransformer {
return { request, response ->
timber.i("Response: $response")
logger.info("($tag) Response: $response")
next(request, response)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import androidx.lifecycle.ViewModel
import com.github.kittinunf.fuel.core.FuelError
import com.stripe.android.connectsdk.FetchClientSecretCallback.ClientSecretResultCallback
import com.stripe.android.connectsdk.PrivateBetaConnectSDK
import com.stripe.android.connectsdk.example.BuildConfig
import com.stripe.android.connectsdk.example.networking.EmbeddedComponentService
import com.stripe.android.connectsdk.example.networking.Merchant
import com.stripe.android.core.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber

class AccountOnboardingExampleViewModel(
private val embeddedComponentService: EmbeddedComponentService = EmbeddedComponentService(),
private val networkingScope: CoroutineScope = CoroutineScope(Dispatchers.IO),
private val logger: Logger = Logger.getInstance(enableLogging = BuildConfig.DEBUG),
) : ViewModel() {

private val timber get() = Timber.tag("AccountOnboardingExampleViewModel")

private val _state = MutableStateFlow(PayoutsExampleState())
val state: StateFlow<PayoutsExampleState> = _state.asStateFlow()

Expand All @@ -38,7 +38,7 @@ class AccountOnboardingExampleViewModel(
resultCallback.onResult(clientSecret)
} catch (e: FuelError) {
resultCallback.onError()
timber.e("Error fetching client secret: $e")
logger.error("(AccountOnboardingExampleViewModel) Error fetching client secret: $e")
}
}
}
Expand All @@ -60,7 +60,7 @@ class AccountOnboardingExampleViewModel(
)
}
} catch (e: FuelError) {
timber.e("Error getting accounts: $e")
logger.error("(AccountOnboardingExampleViewModel) Error getting accounts: $e")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ import androidx.lifecycle.ViewModel
import com.github.kittinunf.fuel.core.FuelError
import com.stripe.android.connectsdk.FetchClientSecretCallback.ClientSecretResultCallback
import com.stripe.android.connectsdk.PrivateBetaConnectSDK
import com.stripe.android.connectsdk.example.BuildConfig
import com.stripe.android.connectsdk.example.networking.EmbeddedComponentService
import com.stripe.android.connectsdk.example.networking.Merchant
import com.stripe.android.core.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import timber.log.Timber

class PayoutsExampleViewModel(
private val embeddedComponentService: EmbeddedComponentService = EmbeddedComponentService(),
private val networkingScope: CoroutineScope = CoroutineScope(Dispatchers.IO),
private val logger: Logger = Logger.getInstance(enableLogging = BuildConfig.DEBUG),
) : ViewModel() {

private val timber get() = Timber.tag("PayoutsExampleViewModel")

private val _state = MutableStateFlow(PayoutsExampleState())
val state: StateFlow<PayoutsExampleState> = _state.asStateFlow()

Expand All @@ -38,7 +38,7 @@ class PayoutsExampleViewModel(
resultCallback.onResult(clientSecret)
} catch (e: FuelError) {
resultCallback.onError()
timber.e("Error fetching client secret: $e")
logger.error("(PayoutsExampleViewModel) Error fetching client secret: $e")
}
}
}
Expand All @@ -60,7 +60,7 @@ class PayoutsExampleViewModel(
)
}
} catch (e: FuelError) {
timber.e("Error getting accounts: $e")
logger.error("(PayoutsExampleViewModel) Error getting accounts: $e")
}
}
}
Expand Down

0 comments on commit 9372621

Please sign in to comment.