From 58eae51d40efcd11763449a79d07d12adf0c0a0c Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Thu, 1 Dec 2022 15:03:29 +0100 Subject: [PATCH] Shorten metadata logging --- .../Processing/MetadataInfoLogger.swift | 54 +++++++++++++------ Sources/Generator/run.swift | 1 + 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/Sources/Generator/Processing/MetadataInfoLogger.swift b/Sources/Generator/Processing/MetadataInfoLogger.swift index 2400f57..d5baa78 100644 --- a/Sources/Generator/Processing/MetadataInfoLogger.swift +++ b/Sources/Generator/Processing/MetadataInfoLogger.swift @@ -128,25 +128,49 @@ final class MetadataInfoLogger { } func printMetadataScanOverview() { - 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)") + var notes = [String]() + func addIfNotZero(_ sequence: Array, _ 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(" 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)" } - lines += ["Warnings:"] + warnings.map { "\($0.source): \($0.message)" } - lines += ["Unreadable files:"] + unreadableMetadata.map { "\($0.source): \($0.error)" } - lines += ["Unused properties:"] + unusedProperties.map { "\($0.source): \($0.name)" } - lines += ["Invalid properties:"] + invalidProperties.map { "\($0.source): \($0.name) (\($0.reason))" } - lines += ["Unknown properties:"] + unknownProperties.map { "\($0.source): \($0.name)" } - lines += ["Missing properties:"] + missingProperties.map { "\($0.source): \($0.name)" } + 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) diff --git a/Sources/Generator/run.swift b/Sources/Generator/run.swift index 062417e..ebf19e1 100644 --- a/Sources/Generator/run.swift +++ b/Sources/Generator/run.swift @@ -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 }