-
Notifications
You must be signed in to change notification settings - Fork 6
Add network logging support #63
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
6052f3c
Add network logging support
stevensJourney dbedeba
add unit test for logs
stevensJourney caeb66c
Merge remote-tracking branch 'origin/main' into network-logging
stevensJourney b906368
update naming in protocols
stevensJourney 782056f
update demo to use latest naming
stevensJourney 45750cc
Merge remote-tracking branch 'origin/main' into network-logging
stevensJourney 503f10a
Add init which accepts LoggerProtocol. Generally cleanup logger config.
stevensJourney 1d59168
update Kotlin core
stevensJourney 12b87b5
fix typos
stevensJourney f018662
Add disconnectAndClear to test
stevensJourney 846cb9d
stop AI from falsely complaining
stevensJourney 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
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,29 @@ | ||
import PowerSyncKotlin | ||
|
||
extension SyncRequestLogLevel { | ||
func toKotlin() -> SwiftSyncRequestLogLevel { | ||
switch self { | ||
case .all: | ||
return SwiftSyncRequestLogLevel.all | ||
case .headers: | ||
return SwiftSyncRequestLogLevel.headers | ||
case .body: | ||
return SwiftSyncRequestLogLevel.body | ||
case .info: | ||
return SwiftSyncRequestLogLevel.info | ||
case .none: | ||
return SwiftSyncRequestLogLevel.none | ||
} | ||
} | ||
} | ||
|
||
extension SyncRequestLoggerConfiguration { | ||
func toKotlinConfig() -> SwiftRequestLoggerConfig { | ||
return SwiftRequestLoggerConfig( | ||
logLevel: self.logLevel.toKotlin(), | ||
log: { [logger] message in | ||
logger.log(message) | ||
} | ||
) | ||
} | ||
} |
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,54 @@ | ||
/// A logger which handles PowerSync network request logs. | ||
/// | ||
/// Implement this protocol to receive network request logging messages at the level | ||
/// specified in `SyncRequestLoggerConfiguration`. The `log(_:)` method will be called | ||
/// for each network event that meets the configured logging criteria. | ||
public protocol SyncRequestLogger { | ||
/// Logs a network-related message. | ||
/// - Parameter message: The formatted log message to record | ||
func log(_ message: String) | ||
} | ||
|
||
/// Level of logs to expose to a `SyncRequestLogger` handler. | ||
/// | ||
/// Controls the verbosity of network logging for PowerSync HTTP requests. | ||
/// The log level is configured once during initialization and determines | ||
/// which network events will be logged throughout the session. | ||
public enum SyncRequestLogLevel { | ||
/// Log all network activity including headers, body, and info | ||
case all | ||
/// Log only request/response headers | ||
case headers | ||
/// Log only request/response body content | ||
case body | ||
/// Log basic informational messages about requests | ||
case info | ||
/// Disable all network logging | ||
case none | ||
} | ||
|
||
/// Configuration for PowerSync HTTP request logging. | ||
/// | ||
/// This configuration is set once during initialization and used throughout | ||
/// the PowerSync session. The `logLevel` determines which network events | ||
/// are logged, while the `logger` handles the actual log output. | ||
/// | ||
/// - Note: The log level cannot be changed after initialization. A new call to `PowerSyncDatabase.connect` is required to change the level. | ||
public struct SyncRequestLoggerConfiguration { | ||
/// The logging level that determines which network events are logged. | ||
/// Set once during initialization and used throughout the session. | ||
public let logLevel: SyncRequestLogLevel | ||
|
||
/// The logger instance that receives network request log messages. | ||
/// Must conform to `SyncRequestLogger` protocol. | ||
public let logger: SyncRequestLogger | ||
|
||
/// Creates a new network logger configuration. | ||
/// - Parameters: | ||
/// - logLevel: The `SyncRequestLogLevel` to use for filtering log messages | ||
/// - logger: A `SyncRequestLogger` instance to handle log output | ||
public init(logLevel: SyncRequestLogLevel, logger: SyncRequestLogger) { | ||
self.logLevel = logLevel | ||
self.logger = logger | ||
} | ||
} |
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
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.