Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 7 additions & 2 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ jobs:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- name: Set up XCode
if: runner.os == 'macOS'
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: latest-stable
- name: Build and Test
run: |
xcodebuild test -scheme PowerSync -destination "platform=iOS Simulator,name=iPhone 15"
xcodebuild test -scheme PowerSync -destination "platform=iOS Simulator,name=iPhone 16"
xcodebuild test -scheme PowerSync -destination "platform=macOS,arch=arm64,name=My Mac"
xcodebuild test -scheme PowerSync -destination "platform=watchOS Simulator,arch=arm64"
xcodebuild test -scheme PowerSync -destination "platform=watchOS Simulator,arch=arm64name=Apple Watch Ultra 2"
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

* [Internal] Instantiate Kotlin Kermit logger directly.

## 1.4.0

* Added the ability to log PowerSync sync network requests.
Expand Down
21 changes: 17 additions & 4 deletions Sources/PowerSync/Kotlin/DatabaseLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,23 @@ private class KermitLogWriterAdapter: Kermit_coreLogWriter {
}
}

class KotlinKermitLoggerConfig: PowerSyncKotlin.Kermit_coreLoggerConfig {
var logWriterList: [Kermit_coreLogWriter]
var minSeverity: PowerSyncKotlin.Kermit_coreSeverity

init(logWriterList: [Kermit_coreLogWriter], minSeverity: PowerSyncKotlin.Kermit_coreSeverity) {
self.logWriterList = logWriterList
self.minSeverity = minSeverity
}
}

/// A logger implementation that integrates with PowerSync's Kotlin core using Kermit.
///
/// This class bridges Swift log writers with the Kotlin logging system and supports
/// runtime configuration of severity levels and writer lists.
class DatabaseLogger: LoggerProtocol {
/// The underlying Kermit logger instance provided by the PowerSyncKotlin SDK.
public let kLogger = PowerSyncKotlin.generateLogger(logger: nil)
public let kLogger: PowerSyncKotlin.KermitLogger
public let logger: any LoggerProtocol

/// Initializes a new logger with an optional list of writers.
Expand All @@ -55,9 +65,12 @@ class DatabaseLogger: LoggerProtocol {
init(_ logger: any LoggerProtocol) {
self.logger = logger
// Set to the lowest severity. The provided logger should filter by severity
kLogger.mutableConfig.setMinSeverity(Kermit_coreSeverity.verbose)
kLogger.mutableConfig.setLogWriterList(
[KermitLogWriterAdapter(logger: logger)]
self.kLogger = PowerSyncKotlin.KermitLogger(
config: KotlinKermitLoggerConfig(
logWriterList: [KermitLogWriterAdapter(logger: logger)],
minSeverity: Kermit_coreSeverity.verbose
),
tag: "PowerSync"
)
}

Expand Down
Loading