diff --git a/Sources/ElixxirDAppsSDK/LogLevelConfigurator.swift b/Sources/ElixxirDAppsSDK/LogLevelConfigurator.swift new file mode 100644 index 0000000000000000000000000000000000000000..cbc8f58a5bbedaf5719375b5f2b61b73697c7b32 --- /dev/null +++ b/Sources/ElixxirDAppsSDK/LogLevelConfigurator.swift @@ -0,0 +1,33 @@ +import Bindings + +public struct LogLevelConfigurator { + public var set: (LogLevel) throws -> Void + + public func callAsFunction(logLevel: LogLevel) throws { + try set(logLevel) + } +} + +extension LogLevelConfigurator { + public static func live() -> LogLevelConfigurator { + LogLevelConfigurator { logLevel in + var error: NSError? + let result = BindingsLogLevel(logLevel.rawValue, &error) + if let error = error { + throw error + } + if !result { + fatalError("BindingsLogLevel returned `false` without providing error") + } + } + } +} + +#if DEBUG +extension LogLevelConfigurator { + public static let failing = LogLevelConfigurator { _ in + struct NotImplemented: Error {} + throw NotImplemented() + } +} +#endif