A simple swift-log-compatible logger designed for GitHub Actions.
Bootstrap the LoggingSystem with GHALogger before creating any logger:
LoggingSystem.bootstrap(GHALogger.init, metadataProvider: nil/* or whatever you want */)A common pattern is to use a GHALogger when running in GitHub Actions and another logger otherwise (e.g. a CLTLogger one):
/* Detect whether process is running in GitHub Actions. */
let isGitHubActionsRun = ProcessInfo.processInfo.environment["GITHUB_ACTIONS"] == "true"
/* Bootstrap the logger and make it available globally. */
LoggingSystem.bootstrap(isGitHubActionsRun ? GHALogger.init : CLTLogger.init, metadataProvider: nil)
/* Create a logger.
* We set the log level to debug if running in GitHub Actions with `RUNNER_DEBUG` set to `1`.
let logger: Logger = {
var ret = Logger(label: "main")
ret.logLevel = (!isGitHubActionsRun || ProcessInfo.processInfo.environment["RUNNER_DEBUG"] != "1") ? .info : .debug
return ret
}()
- Logs with level
critical,error,warningandnoticeare sent as GitHub Actions commands, linked to the file and line that sent the log. Thecriticallevel is logged with an additional colored prefix, to make sure the log is visible. - Logs with level
debugare sent as a GitHub Actions command, though this command is not linked to the file that sent the log (the command does not support it). - Other log levels are logged with specific prefixes, usually with colors.
GitHub Actions supports receiving commands that are parsed on stdout and GHALogger supports sending those commands directly.
Use the GHALogger.sendCommand method to send commands.
For instance, to create a group of lines, do:
if isGitHubActionsRun {GHALogger.sendCommand(.startGroup, withText: "The start of my group.")}
defer {if isGitHubActionsRun {GHALogger.sendCommand(.endGroup)}}
logger.warning("We might have a problem.")
...