2022-08-19 18:05:06 +02:00
|
|
|
|
import Foundation
|
|
|
|
|
|
2022-08-26 17:40:51 +02:00
|
|
|
|
final class ValidationLog {
|
2022-08-19 18:05:06 +02:00
|
|
|
|
|
2022-08-25 00:09:39 +02:00
|
|
|
|
private enum LogLevel: String {
|
|
|
|
|
case error = "ERROR"
|
|
|
|
|
case warning = "WARNING"
|
|
|
|
|
case info = "INFO"
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-19 18:05:06 +02:00
|
|
|
|
init() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-25 00:09:39 +02:00
|
|
|
|
private func add(_ type: LogLevel, item: ContentError) {
|
|
|
|
|
let errorText: String
|
|
|
|
|
if let err = item.error {
|
|
|
|
|
errorText = ", Error: \(err.localizedDescription)"
|
|
|
|
|
} else {
|
|
|
|
|
errorText = ""
|
|
|
|
|
}
|
2022-08-29 19:20:13 +02:00
|
|
|
|
print("[\(type.rawValue)][\(item.source)] \(item.reason)\(errorText)")
|
2022-08-25 00:09:39 +02:00
|
|
|
|
}
|
|
|
|
|
|
2022-08-19 18:05:06 +02:00
|
|
|
|
func add(error: ContentError) {
|
2022-08-25 00:09:39 +02:00
|
|
|
|
add(.error, item: error)
|
2022-08-19 18:05:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func add(error reason: String, source: String, error: Error? = nil) {
|
|
|
|
|
add(error: .init(reason: reason, source: source, error: error))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func add(warning: ContentError) {
|
2022-08-25 00:09:39 +02:00
|
|
|
|
add(.warning, item: warning)
|
2022-08-19 18:05:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func add(warning reason: String, source: String, error: Error? = nil) {
|
|
|
|
|
add(warning: .init(reason: reason, source: source, error: error))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func add(info: ContentError) {
|
2022-08-25 00:09:39 +02:00
|
|
|
|
add(.info, item: info)
|
2022-08-19 18:05:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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")")
|
|
|
|
|
}
|
|
|
|
|
}
|