Skip to content

Commit

Permalink
more logging cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aboedo committed Feb 9, 2021
1 parent d442424 commit 58dfa2c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import com.revenuecat.purchases.PurchasesErrorCode
import com.revenuecat.purchases.common.Backend
import com.revenuecat.purchases.common.LogIntent
import com.revenuecat.purchases.common.caching.DeviceCache
import com.revenuecat.purchases.common.errorLog
import com.revenuecat.purchases.common.log
import com.revenuecat.purchases.strings.IdentityStrings
import com.revenuecat.purchases.strings.IdentityStrings.LOGGING_IN
import com.revenuecat.purchases.strings.IdentityStrings.LOG_OUT_SUCCESSFUL
import com.revenuecat.purchases.subscriberattributes.caching.SubscriberAttributesCache
import java.util.Locale
import java.util.UUID
Expand Down Expand Up @@ -57,7 +60,8 @@ class IdentityManager(
onError: (PurchasesError) -> Unit
) {
if (newAppUserID.isBlank()) {
onError(PurchasesError(PurchasesErrorCode.InvalidAppUserIdError, "appUserID can't be null, empty or blank"))
onError(PurchasesError(PurchasesErrorCode.InvalidAppUserIdError,
"appUserID can't be null, empty or blank").also { errorLog(it) })
return
}

Expand All @@ -68,7 +72,7 @@ class IdentityManager(
newAppUserID,
{ purchaserInfo, created ->
synchronized(this@IdentityManager) {
log(LogIntent.USER, IdentityStrings.CREATING_ALIAS_SUCCESS)
log(LogIntent.USER, IdentityStrings.LOG_IN_SUCCESSFUL.format(newAppUserID, created))
deviceCache.clearCachesForAppUserID(oldAppUserID)
subscriberAttributesCache.clearSubscriberAttributesIfSyncedForSubscriber(oldAppUserID)

Expand Down Expand Up @@ -113,11 +117,12 @@ class IdentityManager(
@Synchronized
fun logOut(): PurchasesError? {
if (currentUserIsAnonymous()) {
log(LogIntent.RC_ERROR, "Called logOut but the current user is anonymous")
log(LogIntent.RC_ERROR, LOGGING_IN)
return PurchasesError(PurchasesErrorCode.LogOutWithAnonymousUserError)
}
deviceCache.clearLatestAttributionData(currentAppUserID)
reset()
log(LogIntent.USER, LOG_OUT_SUCCESSFUL)
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -629,15 +629,13 @@ class Purchases @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) intern
identityManager.currentAppUserID.takeUnless { it == newAppUserID }?.let {
identityManager.logIn(newAppUserID,
onSuccess = { purchaserInfo, created ->
debugLog("login success, purchaserInfo: $purchaserInfo \n created: $created")
dispatch {
listener?.onReceived(purchaserInfo, created)
sendUpdatedPurchaserInfoToDelegateIfChanged(purchaserInfo)
}
fetchAndCacheOfferings(newAppUserID, state.appInBackground)
},
onError = { error ->
debugLog("login error: $error")
dispatch { listener?.onError(error) }
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ object IdentityStrings {
const val CHANGING_APP_USER_ID = "Changing App User ID: %s -> %s"
const val CREATING_ALIAS = "Creating an alias to %s from %s"
const val LOGGING_IN = "Logging in from %s -> %s"
const val LOG_IN_SUCCESSFUL = "Logged in successfully as %s. Created: %s"
const val CREATING_ALIAS_SUCCESS = "Alias created"
const val IDENTIFYING_ANON_ID = "Identifying from an anonymous ID: %s. An alias will be created."
const val IDENTIFYING_APP_USER_ID = "Identifying App User ID: %s"
const val SETTING_NEW_ANON_ID = "Setting new anonymous App User ID - %s"
const val LOG_OUT_CALLED_ON_ANONYMOUS_USER = "Called logOut but the current user is anonymous"
const val LOG_OUT_SUCCESSFUL = "Logged out successfully"
}

0 comments on commit 58dfa2c

Please sign in to comment.