Sub topic 10
Viewing and downloading logs
This chapter assumes you can open a workflow run in the Actions tab and read a simple workflow file. It also assumes you know what a run attempt is and how debug logging is switched on. Here you will find where the logs are, how to read them in the browser, and how to get them onto your machine.
Where logs live
Every job in a run attempt has its own log. Each step in the job is a collapsible section inside that log. Logs belong to an attempt, so a re-run does not overwrite the output of the earlier attempt. You can still open the older attempt from the attempt selector on the run page.
Debug output appears in two different places, depending on its type.
| Log type | Where to read it |
|---|---|
| Normal step output | The job log in the web interface, and in the downloaded archive |
| Step debug messages | Inside the same step sections, on lines that start with `##[debug]` |
| Runner diagnostic logs | Only in the downloaded log archive, in the `runner-diagnostic-logs` folder |
Reading logs in the web interface
Open the run, then click a job in the left sidebar. The log appears on the right, with one section per step. Failed steps are marked with a red icon and usually expand automatically.
Several controls in the log header help with long logs.
- Search logs filters to lines that match your text. Searching for
erroror the name of a failing test is a fast first pass. - Show timestamps adds a time to each line. Use it to find slow steps or long gaps.
- Show full screen gives the log more room.
- View raw logs opens the plain text without the step grouping. This is handy for
Ctrl+Fover the whole job or for copying a large block. - Download log archive saves every job log of the attempt as a zip file.
Step sections are collapsed groups. Commands that your own steps wrap in ::group:: and ::endgroup:: also become collapsible, so a long build log can stay readable.
Downloading logs
The Download log archive option sits in the gear menu of the job log. You need write access to the repository to use it. The zip contains a folder per job, with one text file per step. With runner diagnostic logging on, it also contains the runner-diagnostic-logs folder.
You can fetch the same archive from the command line. The gh api command follows the redirect that the REST API returns for the download.
# Download all logs for one attempt of a run
gh api repos/OWNER/REPO/actions/runs/1234567890/attempts/1/logs > run-logs.zip
# Download the logs of a single job
gh api repos/OWNER/REPO/actions/jobs/987654321/logs > job-log.txt
# Unpack the archive and look for diagnostic logs
unzip -q run-logs.zip -d run-logs
ls run-logsThe run-level endpoint without /attempts/1 returns the logs of the latest attempt. The job-level endpoint returns plain text, not a zip file.
Reading logs without leaving the terminal
You do not always need a zip file. gh run view prints logs directly.
# Logs of failed steps only
gh run view 1234567890 --log-failed
# Full log of one job
gh run view --job 987654321 --log
# Search the full log of a run
gh run view 1234567890 --log | grep -n "Error"Use --log-failed first. It shows only the steps that failed, which is usually where the cause is. Switch to --log when the real error happened earlier than the step that reported it.
Common problems
- The log is missing or says it expired. Logs are kept for a retention period, 90 days by default. After that, both the interface and the API return no log.
- You are reading the wrong attempt. After a re-run, the run page shows the latest attempt. Use the attempt selector, or the
/attempts/Nendpoint, to compare the failed attempt with the passing one. - No
##[debug]lines appear. Step debug logging was not on when that attempt ran. Enabling it later does not add debug output to an attempt that already finished. You must re-run. - There is no
runner-diagnostic-logsfolder. Runner diagnostic logging was off for that attempt. The folder appears only when it was enabled. - A secret shows as ``.* GitHub masks registered secret values in logs. Masking is by exact value, so a transformed secret, such as a base64 copy, may not be masked.
Exercise
A job failed, you re-ran it with step debug logging on, and it failed again. Name two places to look, and say which of them needs a downloaded archive.
Show answer
Open the job log in the web interface (or run gh run view --job JOB_ID --log) and look for ##[debug] lines inside the failing step. The runner diagnostic logs are the second place. They exist only in the runner-diagnostic-logs folder of the downloaded log archive, and only if runner diagnostic logging was enabled for that attempt.