Shorten metadata logging

This commit is contained in:
Christoph Hagen 2022-12-01 15:03:29 +01:00
parent 27b8d5b3ee
commit 58eae51d40
2 changed files with 40 additions and 15 deletions

View File

@ -128,25 +128,49 @@ final class MetadataInfoLogger {
}
func printMetadataScanOverview() {
var notes = [String]()
func addIfNotZero<S>(_ sequence: Array<S>, _ name: String) {
guard sequence.count > 0 else {
return
}
notes.append("\(sequence.count) \(name)")
}
addIfNotZero(warnings, "warnings")
addIfNotZero(errors, "errors")
addIfNotZero(unreadableMetadata, "unreadable files")
addIfNotZero(unusedProperties, "unused properties")
addIfNotZero(invalidProperties, "invalidProperties")
addIfNotZero(unknownProperties, "unknownProperties")
addIfNotZero(missingProperties, "missingProperties")
print(" Number of pages: \(numberOfMetadataFiles)")
print(" Warnings: \(warnings.count)")
print(" Errors: \(errors.count)")
print(" Unreadable files: \(unreadableMetadata.count)")
print(" Unused properties: \(unusedProperties.count)")
print(" Invalid properties: \(invalidProperties.count)")
print(" Unknown properties: \(unknownProperties.count)")
print(" Missing properties: \(missingProperties.count)")
print(" Notes: " + notes.joined(separator: ", "))
}
func writeResultsToFile(in folder: URL) throws {
let url = folder.appendingPathComponent("Metadata issues.txt")
var lines = ["Errors:"] + errors.map { "\($0.source): \($0.message)" }
var lines: [String] = []
if !errors.isEmpty {
lines += ["Errors:"] + errors.map { "\($0.source): \($0.message)" }
}
if !warnings.isEmpty {
lines += ["Warnings:"] + warnings.map { "\($0.source): \($0.message)" }
}
if !unreadableMetadata.isEmpty {
lines += ["Unreadable files:"] + unreadableMetadata.map { "\($0.source): \($0.error)" }
}
if !unusedProperties.isEmpty {
lines += ["Unused properties:"] + unusedProperties.map { "\($0.source): \($0.name)" }
}
if !invalidProperties.isEmpty {
lines += ["Invalid properties:"] + invalidProperties.map { "\($0.source): \($0.name) (\($0.reason))" }
}
if !unknownProperties.isEmpty {
lines += ["Unknown properties:"] + unknownProperties.map { "\($0.source): \($0.name)" }
}
if !missingProperties.isEmpty {
lines += ["Missing properties:"] + missingProperties.map { "\($0.source): \($0.name)" }
}
let data = lines.joined(separator: "\n").data(using: .utf8)
try data?.createFolderAndWrite(to: url)

View File

@ -23,6 +23,7 @@ private func loadSiteData(in folder: URL) throws -> Element? {
let root = Element(atRoot: folder, log: log)
print(" ")
log.printMetadataScanOverview()
print(" ")
try log.writeResultsToFile(in: files.generatorInfoFolder)
return root
}