Sub topic 10
Turning on debug logging
This chapter assumes you can read a workflow file, know the layout of a run page, and can find the failing step in a log. It also assumes you have used the gh CLI to list runs and fetch logs. If any of that is new, review the earlier chapters on run navigation, log structure, and the gh CLI first.
Most failures are visible in the default log. Sometimes they are not. A step exits with code 1 and prints one vague line. A cache restore silently misses. An action reports success but behaves oddly. In these cases, debug logging can show what the runner and the actions were doing.
What debug logging adds
GitHub Actions has two separate debug features. Both are controlled by variables or by a re-run option, and they do different things.
| Feature | Variable | Value | What it adds |
|---|---|---|---|
| Runner diagnostic logging | `ACTIONS_RUNNER_DEBUG` | `true` | Extra lines from the runner process, such as how it set up the job, resolved actions, and handled each step. Also adds diagnostic log files to the downloadable log archive. |
| Step debug logging | `ACTIONS_STEP_DEBUG` | `true` | Messages that actions write with the `::debug::` workflow command, plus extra detail from some built-in steps. |
In practice, step debug logging is the one you reach for first. It is the one that makes actions/cache, actions/setup-node, and many third-party actions explain their decisions. Runner diagnostic logging is most useful when the problem is the runner itself: a job that stalls during setup, an action that fails to download, or an unexplained cancellation.
Debug lines appear in the log with a ##[debug] prefix. In the web interface they are shown in a distinct color, so they are easy to tell apart from normal output.
##[debug]Evaluating condition for step: 'Run npm ci'
##[debug]Evaluating: success()
##[debug]Evaluating success:
##[debug]=> true
##[debug]Result: trueThe lines above show the runner deciding whether a step should run. If a step is skipped and you do not know why, this kind of trace shows how the condition was evaluated.
Three ways to turn it on
You can enable debug logging in three ways. They differ in scope and in whether you have to change repository settings.
- Re-run with debug logging. On the run page, choose Re-run jobs, then tick Enable debug logging in the dialog. This applies to that re-run only. Nothing else in the repository changes.
- Use the
ghCLI. Rungh run rerun <run-id> --debug. This is the same as the checkbox. - Set a secret or variable. Create
ACTIONS_STEP_DEBUGorACTIONS_RUNNER_DEBUGwith the valuetrue. This affects every future run until you remove it.
The first two are almost always the better choice. They are temporary, they leave no setting behind, and they cannot affect runs you do not care about.
# Find the failed run
gh run list --status failure --limit 5
# Re-run only the failed jobs with debug logging
gh run rerun <run-id> --failed --debug
# Show only the failed steps' logs from the new attempt
gh run view <run-id> --log-failedA re-run keeps the same run ID and increments the attempt number. When you view logs afterward, make sure you are reading the latest attempt. The run page has an attempt selector near the top. The gh CLI shows the latest attempt unless you ask for another one.
Setting the repository variable
If you need debug output on every run, for example while you investigate an intermittent failure, add the setting at the repository level. In the repository, open Settings, then Secrets and variables, then Actions. Add a secret or a variable named ACTIONS_STEP_DEBUG with the value true.
If both a secret and a variable of the same name exist, the secret takes precedence. Remove the setting when you finish. Left in place, it makes every log longer and slower to read, and it increases the chance that a sensitive value appears in a debug line.
Writing your own debug messages
The ::debug:: workflow command writes a message that appears only when step debug logging is on. This lets you leave diagnostic output in a workflow without cluttering normal runs.
name: Debug demo
on: workflow_dispatch
jobs:
demo:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Inspect environment
run: |
echo "::debug::Working directory is $(pwd)"
echo "::debug::Node is $(command -v node || echo 'not installed')"
echo "Normal output, always visible"Run this normally and you see only the last echo line. Re-run it with debug logging and the two ::debug:: lines appear as ##[debug] entries. The workflow is complete and runs as shown, and you can trigger it with workflow_dispatch from the Actions tab or with gh workflow run.
You can also check at run time whether debug logging is on. The runner.debug context is 1 when it is enabled.
- name: Extra detail only in debug mode
if: runner.debug == '1'
run: |
env | sort
df -hBe careful with env | sort. Printing the full environment can reveal values that are not registered as secrets. Use it for a quick check, then remove it.
What to look for in a debug log
A debug log is long. Read it with a question in mind, not from top to bottom. These are the common questions and where the answers tend to be.
- Why was a step skipped? Look for
Evaluating condition for stepnear the step's name. The lines that follow show each part of theif:expression and its result. - Why did the cache miss? In the
actions/cacheorsetup-nodestep, look for the computed key and the list of restore keys. A key built from a hash of the wrong file, or a file that does not exist at that path, is a common cause. - Which version was resolved? Setup actions often log the version spec they received and the version they picked. This catches cases such as
node-version: 20resolving to a different minor version than your lock file expects. - What did an expression evaluate to? Debug output shows
Evaluating:andResult:lines for expressions inif:and inwith:inputs. - Did the runner have trouble? With runner diagnostic logging on, download the log archive and look at the files in the diagnostics folder. They record job setup, action downloads, and process exits.
Use the browser search on the log page, or grep on a downloaded copy. The gh CLI can do the same on the command line:
gh run view <run-id> --log | grep -n "##\[debug\]" | head -50Worked example: a cache that never hits
Suppose the setup-node step takes a minute on every run even though you set cache: npm. The default log shows only a line saying no cache was found. The project keeps package.json in app/, as in the earlier fixed workflow.
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: app/package-lock.jsonYou re-run with debug logging and search the setup-node step for the key. The debug output shows the cache key that was computed from the hash of the lock file. If the path were wrong, the step would fail earlier with a message that no file matched the dependency path. If the path is right but the key keeps changing, compare the key between two runs. A key that differs every time means the lock file changes during the job, or the hash input differs between runs. A key that is identical but still misses means the earlier run never saved a cache. Caches are saved at the end of a successful job, so a job that always fails never populates one.
That last point matters: the debug log helped you separate three causes that look the same in the normal log. This is the main use of debug logging. It turns "it did not work" into a specific observation you can act on.
Limits and failure modes
- Debug logging does not fix anything. It only shows more. If the root cause is already clear from the default log, skip it.
- It does not apply to a first attempt retroactively. You cannot add debug output to a run that has finished. You have to re-run, or push a new commit with the variable set.
- Pull requests from forks. Secrets are not passed to workflows triggered by forks, so a
ACTIONS_STEP_DEBUGsecret does not take effect there. The re-run option still works if you have permission to re-run. - Permissions. You need write access to the repository to re-run a workflow and to create secrets or variables.
- Log volume. Debug logs can be many times larger than normal ones. The web viewer may be slow, so download the logs or use
gh. - Not every action emits debug messages. An action that never calls
::debug::adds nothing new. In that case, add your own diagnostic steps. - Retention. Logs are kept only for the repository's retention period. Save any debug log you need as evidence before it expires.
Turning it off again
After you finish, confirm you left nothing behind.
- Delete any
ACTIONS_STEP_DEBUGorACTIONS_RUNNER_DEBUGsecret or variable you added. - Remove temporary
env | sortordf -hsteps. - Keep useful
::debug::lines. They cost nothing in normal runs. - Re-run once without debug logging to confirm the workflow passes the normal way.
Exercise
A step with if: success() was skipped, and the default log only shows the step as skipped. You want to see how the condition was evaluated, and you do not want to change any repository settings. What do you do, and where do you look in the output?
Show answer
Re-run the job with debug logging enabled, either through the Enable debug logging option in the re-run dialog or with gh run rerun <run-id> --failed --debug. Then search the log for Evaluating condition for step near the skipped step. The ##[debug] lines that follow show each expression and its result. Usually an earlier step failed, so success() evaluated to false.
Exercise
You added an ACTIONS_STEP_DEBUG secret with the value true for a fork-based pull request, but no ##[debug] lines appear. Why, and what can you do?
Show answer
Secrets are not passed to workflows triggered by pull requests from forks, so the setting is not seen. Use the re-run option with debug logging enabled, or reproduce the run from a branch in the same repository.