import Foundation final class ValidationLog { private enum LogLevel: String { case error = "ERROR" case warning = "WARNING" case info = "INFO" } init() { } private func add(_ type: LogLevel, item: ContentError) { let errorText: String if let err = item.error { errorText = ", Error: \(err.localizedDescription)" } else { errorText = "" } print("[\(type.rawValue)][\(item.source)] \(item.reason)\(errorText)") } func add(error: ContentError) { add(.error, item: error) } func add(error reason: String, source: String, error: Error? = nil) { add(error: .init(reason: reason, source: source, error: error)) } func add(warning: ContentError) { add(.warning, item: warning) } func add(warning reason: String, source: String, error: Error? = nil) { add(warning: .init(reason: reason, source: source, error: error)) } func add(info: ContentError) { add(.info, item: info) } func add(info reason: String, source: String, error: Error? = nil) { add(info: .init(reason: reason, source: source, error: error)) } func failedToOpen(_ file: String, requiredBy source: String, error: Error?) { print("[ERROR] Failed to open file '\(file)' required by \(source): \(error?.localizedDescription ?? "No error provided")") } }