diff --git a/Package.resolved b/Package.resolved index b01d7a92..910cfd99 100644 --- a/Package.resolved +++ b/Package.resolved @@ -64,6 +64,24 @@ "version": "3.0.14" } }, + { + "package": "swift-log", + "repositoryURL": "https://github.com/apple/swift-log.git", + "state": { + "branch": null, + "revision": "74d7b91ceebc85daf387ebb206003f78813f71aa", + "version": "1.2.0" + } + }, + { + "package": "LoggingGitHubActions", + "repositoryURL": "https://github.com/NSHipster/swift-log-github-actions.git", + "state": { + "branch": null, + "revision": "13ce1e95e5b0c5fffa7667214d42e1f316693ef5", + "version": "0.0.1" + } + }, { "package": "SwiftSyntax", "repositoryURL": "https://github.com/apple/swift-syntax.git", diff --git a/Package.swift b/Package.swift index 667833a4..edd2e0e6 100644 --- a/Package.swift +++ b/Package.swift @@ -19,13 +19,15 @@ let package = Package( .package(url: "https://github.com/SwiftDocOrg/Markup.git", .upToNextMinor(from: "0.0.3")), .package(url: "https://github.com/NSHipster/SwiftSyntaxHighlighter.git", .revision("1.0.0")), .package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.0.2")), + .package(url: "https://github.com/apple/swift-log.git", .upToNextMinor(from: "1.2.0")), + .package(url: "https://github.com/NSHipster/swift-log-github-actions.git", .upToNextMinor(from: "0.0.1")), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. // Targets can depend on other targets in this package, and on products in packages which this package depends on. .target( name: "swift-doc", - dependencies: ["ArgumentParser", "SwiftDoc", "SwiftSemantics", "SwiftMarkup", "CommonMarkBuilder", "HypertextLiteral", "Markup", "DCOV", "GraphViz", "SwiftSyntaxHighlighter"] + dependencies: ["ArgumentParser", "SwiftDoc", "SwiftSemantics", "SwiftMarkup", "CommonMarkBuilder", "HypertextLiteral", "Markup", "DCOV", "GraphViz", "SwiftSyntaxHighlighter", "Logging", "LoggingGitHubActions"] ), .target( name: "DCOV", diff --git a/Sources/swift-doc/Subcommands/Generate.swift b/Sources/swift-doc/Subcommands/Generate.swift index 1fbd1f47..761489ae 100644 --- a/Sources/swift-doc/Subcommands/Generate.swift +++ b/Sources/swift-doc/Subcommands/Generate.swift @@ -90,6 +90,8 @@ extension SwiftDoc { let url = outputDirectoryURL.appendingPathComponent(filename) try $0.value.write(to: url, format: format) } + } catch { + logger.error("\(error)") } } } diff --git a/Sources/swift-doc/Supporting Types/Components/Relationships.swift b/Sources/swift-doc/Supporting Types/Components/Relationships.swift index 9615dc49..5ef8f7cf 100644 --- a/Sources/swift-doc/Supporting Types/Components/Relationships.swift +++ b/Sources/swift-doc/Supporting Types/Components/Relationships.swift @@ -86,7 +86,7 @@ struct Relationships: Component { do { svg = try HypertextLiteral.HTML(String(data: graph.render(using: algorithm, to: .svg), encoding: .utf8) ?? "") } catch { - print(error) + logger.error("\(error)") } return #""" diff --git a/Sources/swift-doc/main.swift b/Sources/swift-doc/main.swift index b87fecdd..0cb9e106 100644 --- a/Sources/swift-doc/main.swift +++ b/Sources/swift-doc/main.swift @@ -1,5 +1,17 @@ import ArgumentParser import Foundation +import Logging +import LoggingGitHubActions + +LoggingSystem.bootstrap { label in + if ProcessInfo.processInfo.environment["GITHUB_ACTIONS"] == "true" { + return GitHubActionsLogHandler.standardOutput(label: label) + } else { + return StreamLogHandler.standardOutput(label: label) + } +} + +let logger = Logger(label: "org.swiftdoc.swift-doc") let fileManager = FileManager.default let fileAttributes: [FileAttributeKey : Any] = [.posixPermissions: 0o744] @@ -10,8 +22,7 @@ var standardError = FileHandle.standardError struct SwiftDoc: ParsableCommand { static var configuration = CommandConfiguration( abstract: "A utility for generating documentation for Swift code.", - subcommands: [Generate.self, Coverage.self, Diagram.self], - defaultSubcommand: Generate.self + subcommands: [Generate.self, Coverage.self, Diagram.self] ) }