CHGenerator/Sources/Generator/Files/ValidationLog.swift

53 lines
1.4 KiB
Swift
Raw Normal View History

2022-08-19 18:05:06 +02:00
import Foundation
final class ValidationLog {
2022-08-19 18:05:06 +02:00
private enum LogLevel: String {
case error = "ERROR"
case warning = "WARNING"
case info = "INFO"
}
2022-08-19 18:05:06 +02:00
init() {
}
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-19 18:05:06 +02:00
func add(error: ContentError) {
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) {
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) {
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")")
}
}