-
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 7 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.requestLevel.toKotlin(), | ||
log: { [log] message in | ||
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,83 @@ | ||
/// 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 `requestLevel` determines which network events | ||
/// are logged. | ||
/// | ||
/// - Note: The request levell cannot be changed after initialization. A new call to `PowerSyncDatabase.connect` is required to change the level. | ||
stevensJourney marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
public struct SyncRequestLoggerConfiguration { | ||
/// The request logging level that determines which network events are logged. | ||
/// Set once during initialization and used throughout the session. | ||
public let requestLevel: SyncRequestLogLevel | ||
|
||
private let logHandler: (_ message: String) -> Void | ||
|
||
/// Creates a new network logger configuration. | ||
/// - Parameters: | ||
/// - requestLevel: The `SyncRequestLogLevel` to use for filtering log messages | ||
/// - logHandler: A closure which handles log messages | ||
stevensJourney marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
public init( | ||
requestLevel: SyncRequestLogLevel, | ||
logHandler: @escaping (_ message: String) -> Void) | ||
{ | ||
self.requestLevel = requestLevel | ||
self.logHandler = logHandler | ||
} | ||
|
||
public func log(_ message: String) { | ||
logHandler(message) | ||
} | ||
|
||
/// Creates a new network logger configuration using a `LoggerProtocol` instance. | ||
/// | ||
/// This initializer allows integration with an existing logging framework by adapting | ||
/// a `LoggerProtocol` to conform to `SyncRequestLogger`. The specified `logSeverity` | ||
/// controls the severity level at which log messages are recorded. An optional `logTag` | ||
/// may be used to help categorize logs. | ||
/// | ||
/// - Parameters: | ||
/// - requestLevel: The `SyncRequestLogLevel` to use for filtering which network events are logged. | ||
/// - logger: An object conforming to `LoggerProtocol` that will receive log messages. | ||
/// - logSeverity: The severity level to use for all log messages (defaults to `.debug`). | ||
/// - logTag: An optional tag to include with each log message, for use by the logging backend. | ||
public init( | ||
requestLevel: SyncRequestLogLevel, | ||
logger: LoggerProtocol, | ||
logSeverity: LogSeverity = .debug, | ||
logTag: String? = nil) | ||
{ | ||
self.requestLevel = requestLevel | ||
self.logHandler = { message in | ||
switch logSeverity { | ||
case .debug: | ||
logger.debug(message, tag: logTag) | ||
case .info: | ||
logger.info(message, tag: logTag) | ||
case .warning: | ||
logger.warning(message, tag: logTag) | ||
case .error: | ||
logger.error(message, tag: logTag) | ||
case .fault: | ||
logger.fault(message, tag: logTag) | ||
} | ||
} | ||
} | ||
} |
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.