-
Notifications
You must be signed in to change notification settings - Fork 265
feat: [SDK-4998] enable KMP logger on Mac Catalyst #1714
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
Open
fadi-george
wants to merge
5
commits into
main
Choose a base branch
from
fadi/sdk-4998
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8d0c826
feat(logging): enable KMP Mac Catalyst support
fadi-george 57ef507
fix(logging): make Catalyst validation self-contained
fadi-george 616f2c8
fix(logging): use getLevel() in OSCrashLogger
fadi-george c2f142e
feat(logging): add injectable request sender to OSRemoteLogger
fadi-george b6d545b
ci(build): add Release configuration to Catalyst archive
fadi-george File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule OneSignal-KMP-SDK
updated
12 files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import Foundation | ||
| @_spi(OneSignalInternal) import OneSignalOSCore | ||
|
|
||
| final class CapturingRequestSender { | ||
| let captured = DispatchSemaphore(value: 0) | ||
|
|
||
| private let lock = NSLock() | ||
| private(set) var requests: [URLRequest] = [] | ||
|
|
||
| func send( | ||
| request: URLRequest, | ||
| completion: @escaping (Data?, URLResponse?, Error?) -> Void | ||
| ) { | ||
| lock.lock() | ||
| requests.append(request) | ||
| lock.unlock() | ||
|
|
||
| let response = HTTPURLResponse( | ||
| url: request.url!, | ||
| statusCode: 202, | ||
| httpVersion: nil, | ||
| headerFields: nil | ||
| ) | ||
| DispatchQueue.global().async { | ||
| completion(nil, response, nil) | ||
| self.captured.signal() | ||
| } | ||
| } | ||
|
|
||
| var requestCount: Int { | ||
| lock.lock() | ||
| defer { lock.unlock() } | ||
| return requests.count | ||
| } | ||
|
|
||
| var firstRequest: URLRequest? { | ||
| lock.lock() | ||
| defer { lock.unlock() } | ||
| return requests.first | ||
| } | ||
| } | ||
|
|
||
| let requestSender = CapturingRequestSender() | ||
| let logger = OSRemoteLogger( | ||
| installIdProvider: { "catalyst-host" }, | ||
| onesignalIdProvider: { nil }, | ||
| pushSubscriptionIdProvider: { nil }, | ||
| appStateProvider: { "foreground" }, | ||
| featureFlagsProvider: { [] }, | ||
| remoteLogLevelProvider: { "INFO" }, | ||
| exporterLoggingEnabledProvider: { false }, | ||
| requestSender: requestSender.send | ||
| ) | ||
|
|
||
| precondition(!logger.kmpVersion.isEmpty) | ||
| precondition(!logger.crashStoragePath.isEmpty) | ||
|
|
||
| logger.start() | ||
| logger.log(level: "INFO", message: "Catalyst logger round trip") | ||
|
|
||
| let flushed = DispatchSemaphore(value: 0) | ||
| logger.forceFlush { | ||
| flushed.signal() | ||
| } | ||
| precondition(flushed.wait(timeout: .now() + 5) == .success) | ||
| precondition(requestSender.captured.wait(timeout: .now() + 5) == .success) | ||
|
|
||
| let request = requestSender.firstRequest | ||
| precondition(request?.httpMethod == "POST") | ||
| precondition(request?.url?.path == "/sdk/log") | ||
| precondition(request?.httpBody?.isEmpty == false) | ||
|
|
||
| logger.shutdown() | ||
|
fadi-george marked this conversation as resolved.
|
||
|
|
||
| let requestCountAfterShutdown = requestSender.requestCount | ||
| logger.log(level: "INFO", message: "Must not be exported after shutdown") | ||
| precondition(requestSender.captured.wait(timeout: .now() + 1) == .timedOut) | ||
| precondition(requestSender.requestCount == requestCountAfterShutdown) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.