CHGenerator/Sources/Generator/Files/ValidationLog.swift
2022-12-01 14:50:26 +01:00

53 lines
1.4 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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")")
}
}