Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: extracted all log strings #2600

Merged
merged 1 commit into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
4FCBA84F2A15391B004134BD /* SnapshotTesting+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 576C8A9127D27DDD0058FA6E /* SnapshotTesting+Extensions.swift */; };
4FCBA8512A153940004134BD /* SnapshotTesting in Frameworks */ = {isa = PBXBuildFile; productRef = 4FCBA8502A153940004134BD /* SnapshotTesting */; };
4FD291BE2A1E9A2E0098D1B9 /* StoreKit2TransactionFetcherTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FD291BD2A1E9A2E0098D1B9 /* StoreKit2TransactionFetcherTests.swift */; };
4FF8464D2A32554300617F00 /* DiagnosticsStrings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FF8464C2A32554300617F00 /* DiagnosticsStrings.swift */; };
57032ABF28C13CE4004FF47A /* StoreKit2SettingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57032ABE28C13CE4004FF47A /* StoreKit2SettingTests.swift */; };
57045B3829C514A8001A5417 /* ProductEntitlementMappingDecodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57045B3729C514A8001A5417 /* ProductEntitlementMappingDecodingTests.swift */; };
57045B3A29C51751001A5417 /* GetProductEntitlementMappingOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57045B3929C51751001A5417 /* GetProductEntitlementMappingOperation.swift */; };
Expand Down Expand Up @@ -508,7 +509,6 @@
9A65E07B2591977500DE00B0 /* NetworkStrings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A65E07A2591977500DE00B0 /* NetworkStrings.swift */; };
9A65E0A02591A23200DE00B0 /* OfferingStrings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A65E09F2591A23200DE00B0 /* OfferingStrings.swift */; };
9A65E0A52591A23500DE00B0 /* PurchaseStrings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A65E0A42591A23500DE00B0 /* PurchaseStrings.swift */; };
9A65E0AA2591A23800DE00B0 /* RestoreStrings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A65E0A92591A23800DE00B0 /* RestoreStrings.swift */; };
A524378B284FFF0200E788BD /* AttributionPosterTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = A524378A284FFF0200E788BD /* AttributionPosterTests.swift */; };
A525BF4B26C320D100C354C4 /* SubscriberAttributesManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = A525BF4A26C320D100C354C4 /* SubscriberAttributesManager.swift */; };
A55D08302722368600D919E0 /* SK2BeginRefundRequestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A55D082F2722368600D919E0 /* SK2BeginRefundRequestHelper.swift */; };
Expand All @@ -524,7 +524,6 @@
A56F9AB126990E9200AFC48F /* CustomerInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = A56F9AB026990E9200AFC48F /* CustomerInfo.swift */; };
A5B6CDD8280F3843007629D5 /* AdServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A5B6CDD5280F3843007629D5 /* AdServices.framework */; platformFilters = (ios, maccatalyst, macos, ); settings = {ATTRIBUTES = (Weak, ); }; };
A5F0104E2717B3150090732D /* BeginRefundRequestHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = A5F0104D2717B3150090732D /* BeginRefundRequestHelper.swift */; };
B300E4BF26D436F900B22262 /* LogIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9A65DFDD258AD60A00DE00B0 /* LogIntent.swift */; };
B300E4C026D4371200B22262 /* SKPaymentTransactionExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F591492526B994B400D32E58 /* SKPaymentTransactionExtensionsTests.swift */; };
B300E4C226D439B700B22262 /* IntroEligibilityCalculatorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 37E354B18710B488B8B0D443 /* IntroEligibilityCalculatorTests.swift */; };
B302206A27271BCB008F1A0D /* Decoder+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B302206927271BCB008F1A0D /* Decoder+Extensions.swift */; };
Expand Down Expand Up @@ -933,6 +932,7 @@
4FA696BC2A0020A000D228B1 /* MainThreadMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainThreadMonitor.swift; sourceTree = "<group>"; };
4FCBA8522A1539D0004134BD /* __Snapshots__ */ = {isa = PBXFileReference; lastKnownFileType = folder; path = __Snapshots__; sourceTree = "<group>"; };
4FD291BD2A1E9A2E0098D1B9 /* StoreKit2TransactionFetcherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2TransactionFetcherTests.swift; sourceTree = "<group>"; };
4FF8464C2A32554300617F00 /* DiagnosticsStrings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiagnosticsStrings.swift; sourceTree = "<group>"; };
57032ABE28C13CE4004FF47A /* StoreKit2SettingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoreKit2SettingTests.swift; sourceTree = "<group>"; };
57045B3729C514A8001A5417 /* ProductEntitlementMappingDecodingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProductEntitlementMappingDecodingTests.swift; sourceTree = "<group>"; };
57045B3929C51751001A5417 /* GetProductEntitlementMappingOperation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GetProductEntitlementMappingOperation.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1164,7 +1164,6 @@
9A65E07A2591977500DE00B0 /* NetworkStrings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetworkStrings.swift; sourceTree = "<group>"; };
9A65E09F2591A23200DE00B0 /* OfferingStrings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OfferingStrings.swift; sourceTree = "<group>"; };
9A65E0A42591A23500DE00B0 /* PurchaseStrings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PurchaseStrings.swift; sourceTree = "<group>"; };
9A65E0A92591A23800DE00B0 /* RestoreStrings.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RestoreStrings.swift; sourceTree = "<group>"; };
A524378A284FFF0200E788BD /* AttributionPosterTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributionPosterTests.swift; sourceTree = "<group>"; };
A525BF4A26C320D100C354C4 /* SubscriberAttributesManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubscriberAttributesManager.swift; sourceTree = "<group>"; };
A55D082F2722368600D919E0 /* SK2BeginRefundRequestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SK2BeginRefundRequestHelper.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1442,14 +1441,14 @@
F5714EE426DC2F1D00635477 /* CodableStrings.swift */,
9A65E03525918B0500DE00B0 /* ConfigureStrings.swift */,
9A65E03A25918B0900DE00B0 /* CustomerInfoStrings.swift */,
4FF8464C2A32554300617F00 /* DiagnosticsStrings.swift */,
575642B52910116900719219 /* EligibilityStrings.swift */,
9A65E0752591977200DE00B0 /* IdentityStrings.swift */,
2D00A41C2767C08300FC3DD8 /* ManageSubscriptionsStrings.swift */,
9A65E07A2591977500DE00B0 /* NetworkStrings.swift */,
9A65E09F2591A23200DE00B0 /* OfferingStrings.swift */,
57488BE729CB7FB60000EE7E /* OfflineEntitlementsStrings.swift */,
9A65E0A42591A23500DE00B0 /* PurchaseStrings.swift */,
9A65E0A92591A23800DE00B0 /* RestoreStrings.swift */,
5791FCF22992D3EC00F1FEDA /* SigningStrings.swift */,
F5C0196826E880800005D61E /* StoreKitStrings.swift */,
37E3507939634ED5A9280544 /* Strings.swift */,
Expand Down Expand Up @@ -3161,6 +3160,7 @@
5791FE4A2994453500F1FEDA /* Signing+ResponseVerification.swift in Sources */,
2DC19195255F36D10039389A /* Logger.swift in Sources */,
2DDF419F24F6F331005BC22D /* ReceiptParsingError.swift in Sources */,
4FF8464D2A32554300617F00 /* DiagnosticsStrings.swift in Sources */,
57BB070E28D27A2B007F5DF0 /* CachingProductsManager.swift in Sources */,
2DDF419D24F6F331005BC22D /* IntroEligibilityCalculator.swift in Sources */,
57536A2627851FFE00E2AE7F /* SK1StoreTransaction.swift in Sources */,
Expand Down Expand Up @@ -3216,7 +3216,6 @@
57536A28278522B400E2AE7F /* SK2StoreTransaction.swift in Sources */,
2D9C7BB326D838FC006838BE /* UIApplication+RCExtensions.swift in Sources */,
F56E2E7727622B5E009FED5B /* TransactionsManager.swift in Sources */,
9A65E0AA2591A23800DE00B0 /* RestoreStrings.swift in Sources */,
B34605CC279A6E380031CA74 /* LogInOperation.swift in Sources */,
35F82BB626A9B8040051DF03 /* AttributionDataMigrator.swift in Sources */,
A55D08302722368600D919E0 /* SK2BeginRefundRequestHelper.swift in Sources */,
Expand Down Expand Up @@ -3479,7 +3478,6 @@
574A2F4F282D7B9E00150D40 /* PostOfferDecodingTests.swift in Sources */,
2DDF41CE24F6F4C3005BC22D /* InAppPurchaseBuilderTests.swift in Sources */,
573A10DB2800AF4700F976E5 /* PurchaseErrorTests.swift in Sources */,
B300E4BF26D436F900B22262 /* LogIntent.swift in Sources */,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unnecessarily being compiled for the Unit Tests target as well.

351B513F26D4496000BD2BD7 /* MockIdentityManager.swift in Sources */,
B319514926C19856002CA9AC /* NSData+RCExtensionsTests.swift in Sources */,
5733B1A427FF9F8300EC2045 /* NetworkErrorTests.swift in Sources */,
Expand Down
8 changes: 8 additions & 0 deletions Sources/Logging/Strings/ConfigureStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ enum ConfigureStrings {

case custom_entitlements_computation_enabled_but_no_app_user_id

case timeout_lower_than_minimum(timeout: TimeInterval, minimum: TimeInterval)

}

extension ConfigureStrings: CustomStringConvertible {
Expand Down Expand Up @@ -167,6 +169,12 @@ extension ConfigureStrings: CustomStringConvertible {
return "customEntitlementComputation mode is enabled, but appUserID is nil. " +
"When using customEntitlementComputation, you must set the appUserID to prevent anonymous IDs from " +
"being generated."

case let .timeout_lower_than_minimum(timeout, minimum):
return """
Timeout value: \(timeout) is lower than the minimum, setting it
to the mimimum: (\(minimum))
"""
}
}

Expand Down
34 changes: 34 additions & 0 deletions Sources/Logging/Strings/DiagnosticsStrings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// DiagnosticsStrings.swift
//
// Created by Nacho Soto on 6/8/23.

import Foundation

// swiftlint:disable identifier_name

enum DiagnosticsStrings {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started this, which will grow more with the upcoming diagnostics.


case timing_message(message: String, duration: TimeInterval)

}

extension DiagnosticsStrings: CustomStringConvertible {

var description: String {
switch self {
case let .timing_message(message, duration):
let roundedDuration = (duration * 100).rounded(.down) / 100
return String(format: "%@ (%.2f seconds)", message.description, roundedDuration)
}
}

}
4 changes: 4 additions & 0 deletions Sources/Logging/Strings/NetworkStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ enum NetworkStrings {
case failing_url_resolved_to_host(url: URL, resolvedHost: String)
case blocked_network(url: URL, newHost: String?)
case api_request_redirect(from: URL, to: URL)
case operation_state(NetworkOperation.Type, state: String)

#if DEBUG
case api_request_forcing_server_error(HTTPRequest)
Expand Down Expand Up @@ -103,6 +104,9 @@ extension NetworkStrings: CustomStringConvertible {
case let .api_request_redirect(from, to):
return "Performing redirect from '\(from.absoluteString)' to '\(to.absoluteString)'"

case let .operation_state(operation, state):
return "\(operation): \(state)"

#if DEBUG
case let .api_request_forcing_server_error(request):
return "Returning fake HTTP 500 error for '\(request.description)'"
Expand Down
4 changes: 4 additions & 0 deletions Sources/Logging/Strings/OfferingStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ enum OfferingStrings {
case product_details_empty_title(productIdentifier: String)
case unknown_package_type(Package)
case custom_package_type(Package)
case overriding_package(old: String, new: String)

}

Expand Down Expand Up @@ -151,6 +152,9 @@ extension OfferingStrings: CustomStringConvertible {
"has a custom duration." +
"\nYou can reference this package by its identifier ('\(package.identifier)') directly." +
"\nMore information: https://rev.cat/displaying-products"

case let .overriding_package(old, new):
return "Package: \(old) already exists, overwriting with: \(new)"
}
}

Expand Down
11 changes: 11 additions & 0 deletions Sources/Logging/Strings/PurchaseStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ enum PurchaseStrings {
case sk2_transactions_update_received_transaction(StoreTransaction)
case sk1_purchase_too_slow
case sk2_purchase_too_slow
case payment_queue_wrapper_delegate_call_sk1_enabled

// swiftlint:disable:next identifier_name
case restorepurchases_called_with_allow_sharing_appstore_account_false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick and it was like this before but should this be restore_purchases_called_with_allow_sharing_appstore_account_false

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it was like this because the method is restorePurchases, so this is one word to signal that.


}

Expand Down Expand Up @@ -282,6 +286,13 @@ extension PurchaseStrings: CustomStringConvertible {

case .sk2_purchase_too_slow:
return "StoreKit 2 purchase took longer than expected"

case .payment_queue_wrapper_delegate_call_sk1_enabled:
return "Unexpectedly received PaymentQueueWrapperDelegate call with SK1 enabled"

case .restorepurchases_called_with_allow_sharing_appstore_account_false:
return "allowSharingAppStoreAccount is set to false and restorePurchases has been called. " +
"Are you sure you want to do this?"
}
}

Expand Down
35 changes: 0 additions & 35 deletions Sources/Logging/Strings/RestoreStrings.swift

This file was deleted.

18 changes: 18 additions & 0 deletions Sources/Logging/Strings/StoreKitStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ enum StoreKitStrings {

case sk1_no_known_product_type

case sk1_unknown_transaction_state(SKPaymentTransactionState)

case unknown_sk2_product_discount_type(rawValue: String)

case sk1_discount_missing_locale
Expand All @@ -55,6 +57,12 @@ enum StoreKitStrings {

case sk2_product_request_too_slow

#if DEBUG

case sk1_wrapper_notifying_delegate_of_existing_transactions(count: Int)

#endif

}

extension StoreKitStrings: CustomStringConvertible {
Expand Down Expand Up @@ -101,6 +109,9 @@ extension StoreKitStrings: CustomStringConvertible {
return "This StoreProduct represents an SK1 product, the type of product cannot be determined, " +
"the value will be undefined. Use `StoreProduct.productCategory` instead."

case let .sk1_unknown_transaction_state(state):
return "Received unknown transaction state: \(state.rawValue)"

case .unknown_sk2_product_discount_type(let rawValue):
return "Failed to create StoreProductDiscount.DiscountType with unknown value: \(rawValue)"

Expand Down Expand Up @@ -128,6 +139,13 @@ extension StoreKitStrings: CustomStringConvertible {

case .sk2_product_request_too_slow:
return "StoreKit 2 product request took longer than expected"

#if DEBUG
case let .sk1_wrapper_notifying_delegate_of_existing_transactions(count):
return "StoreKit1Wrapper: sending delegate \(count) existing transactions " +
"for Integration Tests."
#endif

}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Logging/Strings/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ enum Strings {
static let configure = ConfigureStrings.self
static let backendError = BackendErrorStrings.self
static let customerInfo = CustomerInfoStrings.self
static let diagnostics = DiagnosticsStrings.self
static let eligibility = EligibilityStrings.self
static let identity = IdentityStrings.self
static let network = NetworkStrings.self
static let offering = OfferingStrings.self
static let offlineEntitlements = OfflineEntitlementsStrings.self
static let purchase = PurchaseStrings.self
static let receipt = ReceiptStrings.self
static let restore = RestoreStrings.self
static let signing = SigningStrings.self
static let storeKit = StoreKitStrings.self

Expand Down
10 changes: 6 additions & 4 deletions Sources/Misc/DateAndTime/TimingUtil.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ private extension TimingUtil {
intent: LogIntent
) {
if duration >= threshold {
let roundedDuration = (duration * 100).rounded(.down) / 100
let message = String(format: "%@ (%.2f seconds)", message.description, roundedDuration)

Logger.log(level: level, intent: intent, message: message)
Logger.log(
level: level,
intent: intent,
message: Strings.diagnostics.timing_message(message: message.description,
duration: duration)
)
}
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/Networking/Operations/NetworkOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ class NetworkOperation: Operation {
// MARK: -

internal func log(_ message: CustomStringConvertible) {
Logger.debug("\(type(of: self)): \(message.description)")
Logger.debug(Strings.network.operation_state(type(of: self),
state: message.description))
}

// MARK: -
Expand Down
8 changes: 4 additions & 4 deletions Sources/Purchasing/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ import Foundation
private func clamped(timeout: TimeInterval) -> TimeInterval {
guard timeout >= Self.minimumTimeout else {
Logger.warn(
"""
Timeout value: \(timeout) is lower than the minimum, setting it
to the mimimum: (\(Self.minimumTimeout))
"""
Strings.configure.timeout_lower_than_minimum(
timeout: timeout,
minimum: Self.minimumTimeout
)
)
return Self.minimumTimeout
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/Purchasing/Offering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,8 @@ private extension Offering {

static func checkForNilAndLogReplacement(previousPackages: [PackageType: Package], newPackage: Package) {
if let package = previousPackages[newPackage.packageType] {
Logger.warn("Package: \(package.identifier) already exists, overwriting with: \(newPackage.identifier)")
Logger.warn(Strings.offering.overriding_package(old: package.identifier,
new: newPackage.identifier))
}
}

Expand Down
Loading