Skip to content

Changed Logger to use os_log#2608

Merged
NachoSoto merged 10 commits into
mainfrom
os-log
Jun 15, 2023
Merged

Changed Logger to use os_log#2608
NachoSoto merged 10 commits into
mainfrom
os-log

Conversation

@NachoSoto

@NachoSoto NachoSoto commented Jun 8, 2023

Copy link
Copy Markdown
Contributor

Fixes SDK-3173.

Motivation

os_log (and the new Logger.log) is the canonical way of logging in Apple platforms, replacing the old NSLog. This was made even more useful with the updates to log printing in Xcode 15.
Additionally, this allows us in the future to log OSLogMessage (using OSLogInterpolation), and therefore being able to mark certain parts of logs as privacy: .private.

Changes:

  • Introduced LogMessage to ensure every logged message has a category
  • Created LoggerStore to abstract os.Logger creation
  • Changed Logger to use os.Logger if available (defaulting to the old NSLog otherwise)
  • Updated tests to always use LogMessage instances (same as Refactor: extracted all log strings #2600)

With these new categories, log provide extra context. Example

[storeKit] DEBUG: 😻 Store products request received response
[storeKit] DEBUG: ℹ️ Store products request finished
[offering] DEBUG: 😻 Offerings updated from network.
[offering] DEBUG: 😻 Offerings updated from network.
[network] DEBUG: ℹ️ API request completed: GET /v1/product_entitlement_mapping (200)
[offline_entitlements] DEBUG: ℹ️ ProductEntitlementMapping cache updated from network.
[network] DEBUG: ℹ️ GetProductEntitlementMappingOperation: Finished
[network] DEBUG: ℹ️ Serial request done: GET product_entitlement_mapping, 0 requests left in the queue
[network] DEBUG: ℹ️ GetCustomerInfoOperation: Started
[network] DEBUG: ℹ️ There are no requests currently running, starting request GET subscribers/$RCAnonymousID%3A7f0e7d8de70745ada839e66a66ec2d86
[network] DEBUG: ℹ️ API request started: GET /v1/subscribers/$RCAnonymousID:7f0e7d8de70745ada839e66a66ec2d86
[network] DEBUG: ℹ️ API request completed: GET /v1/subscribers/$RCAnonymousID:7f0e7d8de70745ada839e66a66ec2d86 (201)
[customer] VERBOSE: Updating CustomerInfo '$RCAnonymousID:7f0e7d8de70745ada839e66a66ec2d86' request date: 2023-06-13 21:33:34 +0000
[customer] DEBUG: ℹ️ Sending latest CustomerInfo to delegate.
[customer] DEBUG: 😻 CustomerInfo updated from network.
[eligibility] DEBUG: ℹ️ Detected active subscriptions changed. Clearing trial or intro eligibility cache.

These also look much better on Xcode 15:
Screenshot 2023-06-13 at 14 52 57
And even allow users to filter out specific categories:
Screenshot 2023-06-13 at 14 53 09

@NachoSoto NachoSoto requested a review from a team June 8, 2023 21:37
@NachoSoto NachoSoto changed the title Changed Logger to use os_log [WIP] Changed Logger to use os_log Jun 8, 2023
@NachoSoto NachoSoto force-pushed the os-log branch 3 times, most recently from 883a6c1 to 33b21a5 Compare June 13, 2023 20:57
@NachoSoto NachoSoto changed the title [WIP] Changed Logger to use os_log Changed Logger to use os_log Jun 13, 2023
@NachoSoto NachoSoto marked this pull request as ready for review June 13, 2023 20:57
@codecov

codecov Bot commented Jun 14, 2023

Copy link
Copy Markdown

Codecov Report

Merging #2608 (b4f3c99) into main (1b2f7f9) will increase coverage by 0.05%.
The diff coverage is 85.55%.

@@            Coverage Diff             @@
##             main    #2608      +/-   ##
==========================================
+ Coverage   86.31%   86.36%   +0.05%     
==========================================
  Files         207      207              
  Lines       14540    14611      +71     
==========================================
+ Hits        12550    12619      +69     
- Misses       1990     1992       +2     
Impacted Files Coverage Δ
Sources/Purchasing/Purchases/Purchases.swift 75.95% <0.00%> (-0.89%) ⬇️
...urces/LocalReceiptParsing/Helpers/LoggerType.swift 78.46% <92.59%> (+9.23%) ⬆️
Sources/Logging/Logger.swift 94.30% <97.29%> (+0.19%) ⬆️
...s/LocalReceiptParsing/Helpers/ReceiptStrings.swift 84.28% <100.00%> (+0.22%) ⬆️
Sources/Logging/Strings/AttributionStrings.swift 86.27% <100.00%> (+0.13%) ⬆️
Sources/Logging/Strings/BackendErrorStrings.swift 60.00% <100.00%> (+2.85%) ⬆️
Sources/Logging/Strings/CodableStrings.swift 87.50% <100.00%> (+0.40%) ⬆️
Sources/Logging/Strings/ConfigureStrings.swift 86.36% <100.00%> (+0.12%) ⬆️
Sources/Logging/Strings/CustomerInfoStrings.swift 90.00% <100.00%> (+0.20%) ⬆️
Sources/Logging/Strings/DiagnosticsStrings.swift 100.00% <100.00%> (ø)
... and 9 more

... and 5 files with indirect coverage changes

"\(level.description, privacy: .public)\(fileContext, privacy: .public): \(message, privacy: .public)"
)
} else {
NSLog("%@", "[\(framework)] - \(level.description)\(fileContext): \(message)")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Codecov only looks at iOS 16: this is still used before iOS 14.0

@aboedo aboedo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

❤️

@NachoSoto NachoSoto merged commit 7f875ae into main Jun 15, 2023
@NachoSoto NachoSoto deleted the os-log branch June 15, 2023 22:13
NachoSoto pushed a commit that referenced this pull request Jun 22, 2023
**This is an automatic release.**

### Bugfixes
* `PurchasesOrchestrator`: update `CustomerInfoManager` cache after
processing transactions (#2676) via NachoSoto (@NachoSoto)
* `ErrorResponse`: drastically improved error messages, no more "unknown
error"s (#2660) via NachoSoto (@NachoSoto)
* `PaywallExtensions`: post purchases with `Offering` identifier (#2645)
via NachoSoto (@NachoSoto)
* Support `product_plan_identifier` for purchased subscriptions from
`Google Play` (#2654) via Josh Holtz (@joshdholtz)
### Performance Improvements
* `copy(with: VerificationResult)`: optimization to avoid copies (#2639)
via NachoSoto (@NachoSoto)
### Other Changes
* `ETagManager`: refactored e-tag creation and tests (#2671) via
NachoSoto (@NachoSoto)
* `getPromotionalOffer`: return `ErrorCode.ineligibleError` if receipt
is not found (#2678) via NachoSoto (@NachoSoto)
* `TimingUtil`: removed slow purchase logs (#2677) via NachoSoto
(@NachoSoto)
* `CI`: changed `Codecov` to `informational` (#2670) via NachoSoto
(@NachoSoto)
* `LoadShedderIntegrationTests`: verify requests are actually handled by
load shedder (#2663) via NachoSoto (@NachoSoto)
* `ETagManager.httpResultFromCacheOrBackend`: return response headers
(#2666) via NachoSoto (@NachoSoto)
* `Integration Tests`: added tests to verify 304 behavior (#2659) via
NachoSoto (@NachoSoto)
* `HTTPClient`: disable `URLSession` cache (#2668) via NachoSoto
(@NachoSoto)
* Documented `HTTPStatusCode.isSuccessfullySynced` (#2661) via NachoSoto
(@NachoSoto)
* `NetworkError.signatureVerificationFailed`: added status code to error
`userInfo` (#2657) via NachoSoto (@NachoSoto)
* `HTTPClient`: improved log for failed requests (#2669) via NachoSoto
(@NachoSoto)
* `ETagManager`: added new verbose logs (#2656) via NachoSoto
(@NachoSoto)
* `Signature Verification`: added test-only log for debugging invalid
signatures (#2658) via NachoSoto (@NachoSoto)
* Fixed `HTTPResponse.description` (#2664) via NachoSoto (@NachoSoto)
* Changed `Logger` to use `os_log` (#2608) via NachoSoto (@NachoSoto)
* `MainThreadMonitor`: increased threshold (#2662) via NachoSoto
(@NachoSoto)
* `debugRevenueCatOverlay`: display `receiptURL` (#2652) via NachoSoto
(@NachoSoto)
* `PurchaseTester`: added ability to display `debugRevenueCatOverlay`
(#2653) via NachoSoto (@NachoSoto)
* `debugRevenueCatOverlay`: ability to close on `macOS`/`Catalyst`
(#2649) via NachoSoto (@NachoSoto)
* `debugRevenueCatOverlay`: added support for `macOS` (#2648) via
NachoSoto (@NachoSoto)
* `LoadShedderIntegrationTests`: enable signature verification (#2655)
via NachoSoto (@NachoSoto)
* `ImageSnapshot`: fixed Xcode 15 compilation (#2651) via NachoSoto
(@NachoSoto)
* `OfferingsManager`: don't clear offerings cache timestamp when request
fails (#2359) via NachoSoto (@NachoSoto)
* `StoreKitObserverModeIntegrationTests`: added test for posting
renewals (#2590) via NachoSoto (@NachoSoto)
* Always initialize `StoreKit2TransactionListener` even on SK1 mode
(#2612) via NachoSoto (@NachoSoto)
* `ErrorUtils.missingReceiptFileError`: added receipt URL `userInfo`
context (#2650) via NachoSoto (@NachoSoto)
* Added `.xcprivacy` for Xcode 15 (#2619) via NachoSoto (@NachoSoto)
* `Trusted Entitlements`: added debug log with
`ResponseVerificationMode` (#2647) via NachoSoto (@NachoSoto)
* `debugRevenueCatOverlay`: simplified title (#2641) via NachoSoto
(@NachoSoto)
* Simplified `Purchases.updateAllCachesIfNeeded` (#2626) via NachoSoto
(@NachoSoto)
* `HTTPResponseTests`: fixed disabled test (#2643) via NachoSoto
(@NachoSoto)
* Add `InternalDangerousSettings.forceSignatureFailures` (#2635) via
NachoSoto (@NachoSoto)
* `IntegrationTests`: explicit `StoreKit 1` mode (#2636) via NachoSoto
(@NachoSoto)
* `Signing`: removed API for loading key from a file (#2638) via
NachoSoto (@NachoSoto)
NachoSoto added a commit that referenced this pull request Jun 23, 2023
`Purchases.verboseLogHandler` changed in #2608 with the introduction of a new `internalLogHandler`.
Restoring the log handler doing `Purchases.verboseLogHandler = Purchases.verboseLogHandler` now loses the message category.

We didn't have test coverage for `Purchases.logHandler` either which this adds as well.

This also fixes tests in RevenueCat/purchases-hybrid-common#435
NachoSoto added a commit that referenced this pull request Jun 26, 2023
`Purchases.verboseLogHandler` changed in #2608 with the introduction of
a new `internalLogHandler`.
Restoring the log handler doing `Purchases.verboseLogHandler =
Purchases.verboseLogHandler` now loses the message category.

We didn't have test coverage for `Purchases.logHandler` either which
this adds as well.

This also fixes tests in
RevenueCat/purchases-hybrid-common#435
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants