Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

GitHubActionsLogHandler

mattt edited this page Mar 25, 2020 · 1 revision

GitHubActionsLogHandler

A logger for GitHub Actions workflows.

public struct GitHubActionsLogHandler: LogHandler

See "Workflow commands for GitHub Actions."

Inheritance

LogHandler

Properties

logLevel

Get or set the configured log level.

var logLevel: Logger.Level = .debug

metadata

Get or set the entire metadata storage as a dictionary.

var metadata: Logger.Metadata = [:]

Methods

addSystemPath(_:)

Prepends a directory to the system PATH variable for all subsequent actions in the current job.

public func addSystemPath(_ path: String)

The currently running action cannot access the new path variable.

   ::add-path::{path}

Parameters

  • path: The directory path to prepend to the system PATH variable.

log(level:message:metadata:file:function:line:)

Prints a message to the log at the specified level.

public func log(level: Logger.Level, message: Logger.Message, metadata: Logger.Metadata?, file: String, function: String, line: UInt)

This method is called when a LogHandler must emit a log message. There is no need for the LogHandler to check if the level is above or below the configured logLevel as Logger already performed this check and determined that a message should be logged.

   ::{level} file={name},line={line}::{message}

Note: You must create a secret named ACTIONS_STEP_DEBUG with the value true to see the debug messages set by this command in the log. To learn more about creating secrets and using them in a step, see "Creating and using encrypted secrets."

Parameters

  • level: The log level the message was logged at.
  • message: The message to log. To obtain a String representation call message.description.
  • metadata: The metadata associated to this log message.
  • file: The file the log message was emitted from.
  • function: The function the log line was emitted from.
  • line: The line the log message was emitted from.

mask(value:)

Masking a value prevents a string or variable from being printed in the log. Each masked word separated by whitespace is replaced with the * character. You can use an environment variable or string for the mask's value.

public func mask(value: String)
   ::add-mask::{value}

setEnvironmentVariable(name:value:)

Creates or updates an environment variable for any actions running next in a job.

public func setEnvironmentVariable(name: String, value: String)

The action that creates or updates the environment variable does not have access to the new value, but all subsequent actions in a job will have access. Environment variables are case-sensitive and you can include punctuation.

   ::set-env name={name}::{value}

Parameters

  • name: The environment variable name
  • value: The environment variable value

setOutputParameter(name:value:)

Sets an action's output parameter.

public func setOutputParameter(name: String, value: String)

Optionally, you can also declare output parameters in an action's metadata file. For more information, see "Metadata syntax for GitHub Actions."

   ::set-output name={name}::{value}

Parameters

  • name: The environment variable name
  • value: The environment variable value

standardOutput(label:)

Returns a handler that logs to standard output (STDOUT).

public static func standardOutput(label: String) -> GitHubActionsLogHandler

Parameters

  • label: A label identifying the logging handler.

withoutProcessingWorkflowCommands(_:)

Performs the specified closure without processing any workflow commands.

public func withoutProcessingWorkflowCommands(_ body: () -> Void)

You can use this function to log dynamic values without accidentally running a workflow command. For example, you could stop logging to output an entire script that has comments.

   ::stop-commands::{token}
   ...
   ::{token}::

Parameters

  • body: Work to be performed without running workflow commands.