LoggingGitHubActions

一个 SwiftLog 的日志后端,可以将日志消息转换为 GitHub Actions 的工作流命令

要求

用法

有条件地引导 GitHubActionsLogHandler

import Logging
import LoggingGitHubActions
import struct Foundation.ProcessInfo

LoggingSystem.bootstrap { label in
    if ProcessInfo.processInfo.environment["GITHUB_ACTIONS"] == "true" {
        return GitHubActionsLogHandler.standardOutput(label: label)
    } else {
        return StreamLogHandler.standardOutput(label: label)
    }
}

使用 Logger

创建一个 Logger 的实例,并相应地记录消息。当你的程序作为 GitHub Actions 工作流中的一个步骤运行时,警告和错误消息将被格式化,以便在 GitHub Actions UI 中显示。

import Logging

let logger = Logger(label: "com.example.MyApp")
logger.error("Something went wrong")
// Prints "::error file=Sources/main.swift,line=5::Something went wrong

GitHub Actions UI

安装

Swift Package Manager

swift-log-github-actions 添加为你的 Package.swift 文件的依赖项。

.package(url: "https://github.com/NSHipster/swift-log-github-actions.git", from: "1.0.0")

"LoggingGitHubActions 添加到你的目标的依赖项中。

.target(name: "Example",
        dependencies: ["LoggingGitHubActions"])

许可

MIT

联系方式

Mattt (@mattt)