Skip to content

feat: add OSLogSupabaseLogger type #757

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 3 commits into from
Jul 30, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
54 changes: 54 additions & 0 deletions Sources/Helpers/Logger/OSLogSupabaseLogger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import Foundation

#if canImport(OSLog)
import OSLog

/// A SupabaseLogger implementation that logs to OSLog.
///
/// This logger maps Supabase log levels to appropriate OSLog levels:
/// - `.verbose` → `.info`
/// - `.debug` → `.debug`
/// - `.warning` → `.notice`
/// - `.error` → `.error`
///
/// ## Usage
///
/// ```swift
/// let supabaseLogger = OSLogSupabaseLogger()
///
/// // Use with Supabase client
/// let supabase = SupabaseClient(
/// supabaseURL: url,
/// supabaseKey: key,
/// options: .init(global: .init(logger: supabaseLogger))
/// )
/// ```
@available(macOS 11.0, iOS 14.0, tvOS 14.0, watchOS 7.0, *)
public struct OSLogSupabaseLogger: SupabaseLogger {
private let logger: Logger

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (IOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (IOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (IOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (IOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (MAC_CATALYST, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (MAC_CATALYST, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (MAC_CATALYST, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (MAC_CATALYST, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (test, MACOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (test, MACOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (MACOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (MACOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (MACOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (MACOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (test, MAC_CATALYST, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (test, MAC_CATALYST, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (test, IOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

Check warning on line 28 in Sources/Helpers/Logger/OSLogSupabaseLogger.swift

View workflow job for this annotation

GitHub Actions / xcodebuild (15.4) (test, IOS, 15.4)

stored property 'logger' of 'Sendable'-conforming struct 'OSLogSupabaseLogger' has non-sendable type 'Logger'

/// Creates a new OSLog-based logger with a provided Logger instance.
///
/// - Parameter logger: The OSLog Logger instance to use for logging.
public init(
_ logger: Logger = Logger(subsystem: Bundle.main.bundleIdentifier ?? "", category: "Supabase")
) {
self.logger = logger
}

public func log(message: SupabaseLogMessage) {
let logMessage = message.description

switch message.level {
case .verbose:
logger.info("\(logMessage, privacy: .public)")
case .debug:
logger.debug("\(logMessage, privacy: .public)")
case .warning:
logger.notice("\(logMessage, privacy: .public)")
case .error:
logger.error("\(logMessage, privacy: .public)")
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,4 @@ extension SupabaseLogger {
}
}
#endif

Loading