From bf4f9e5da776c8815d37f44801760d417b0d9a99 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Thu, 2 Jun 2022 14:54:01 +0200 Subject: [PATCH] Add LogLevelConfigurator --- .../LogLevelConfigurator.swift | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Sources/ElixxirDAppsSDK/LogLevelConfigurator.swift diff --git a/Sources/ElixxirDAppsSDK/LogLevelConfigurator.swift b/Sources/ElixxirDAppsSDK/LogLevelConfigurator.swift new file mode 100644 index 00000000..cbc8f58a --- /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 -- GitLab