Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit f5c21d6

Browse files
authored
Merge pull request #52 from SwiftDocOrg/mattt/logging-infrastructure
Implement Logging Infrastructure
2 parents 869be1a + c27b644 commit f5c21d6

File tree

5 files changed

+37
-4
lines changed

5 files changed

+37
-4
lines changed

Package.resolved

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ let package = Package(
1919
.package(url: "https://github.com/SwiftDocOrg/Markup.git", .upToNextMinor(from: "0.0.3")),
2020
.package(url: "https://github.com/NSHipster/SwiftSyntaxHighlighter.git", .revision("1.0.0")),
2121
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMinor(from: "0.0.2")),
22+
.package(url: "https://github.com/apple/swift-log.git", .upToNextMinor(from: "1.2.0")),
23+
.package(url: "https://github.com/NSHipster/swift-log-github-actions.git", .upToNextMinor(from: "0.0.1")),
2224
],
2325
targets: [
2426
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2527
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
2628
.target(
2729
name: "swift-doc",
28-
dependencies: ["ArgumentParser", "SwiftDoc", "SwiftSemantics", "SwiftMarkup", "CommonMarkBuilder", "HypertextLiteral", "Markup", "DCOV", "GraphViz", "SwiftSyntaxHighlighter"]
30+
dependencies: ["ArgumentParser", "SwiftDoc", "SwiftSemantics", "SwiftMarkup", "CommonMarkBuilder", "HypertextLiteral", "Markup", "DCOV", "GraphViz", "SwiftSyntaxHighlighter", "Logging", "LoggingGitHubActions"]
2931
),
3032
.target(
3133
name: "DCOV",

Sources/swift-doc/Subcommands/Generate.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ extension SwiftDoc {
9090
let url = outputDirectoryURL.appendingPathComponent(filename)
9191
try $0.value.write(to: url, format: format)
9292
}
93+
} catch {
94+
logger.error("\(error)")
9395
}
9496
}
9597
}

Sources/swift-doc/Supporting Types/Components/Relationships.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ struct Relationships: Component {
8686
do {
8787
svg = try HypertextLiteral.HTML(String(data: graph.render(using: algorithm, to: .svg), encoding: .utf8) ?? "")
8888
} catch {
89-
print(error)
89+
logger.error("\(error)")
9090
}
9191

9292
return #"""

Sources/swift-doc/main.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
import ArgumentParser
22
import Foundation
3+
import Logging
4+
import LoggingGitHubActions
5+
6+
LoggingSystem.bootstrap { label in
7+
if ProcessInfo.processInfo.environment["GITHUB_ACTIONS"] == "true" {
8+
return GitHubActionsLogHandler.standardOutput(label: label)
9+
} else {
10+
return StreamLogHandler.standardOutput(label: label)
11+
}
12+
}
13+
14+
let logger = Logger(label: "org.swiftdoc.swift-doc")
315

416
let fileManager = FileManager.default
517
let fileAttributes: [FileAttributeKey : Any] = [.posixPermissions: 0o744]
@@ -10,8 +22,7 @@ var standardError = FileHandle.standardError
1022
struct SwiftDoc: ParsableCommand {
1123
static var configuration = CommandConfiguration(
1224
abstract: "A utility for generating documentation for Swift code.",
13-
subcommands: [Generate.self, Coverage.self, Diagram.self],
14-
defaultSubcommand: Generate.self
25+
subcommands: [Generate.self, Coverage.self, Diagram.self]
1526
)
1627
}
1728

0 commit comments

Comments
 (0)