[PR #1945] [CLOSED] feat: only print container logs with --focus #2203

Closed
opened 2026-03-01 21:54:26 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/nektos/act/pull/1945
Author: @JeanMertz
Created: 8/5/2023
Status: Closed

Base: masterHead: jean/focus-mode


📝 Commits (1)

  • 819c0a6 feat: only print container logs with --focus

📊 Changes

11 files changed (+78 additions, -10 deletions)

View changed files

📝 cmd/input.go (+1 -0)
📝 cmd/root.go (+7 -0)
📝 pkg/common/logger.go (+18 -0)
📝 pkg/runner/action.go (+4 -1)
📝 pkg/runner/action_composite.go (+4 -1)
📝 pkg/runner/command.go (+1 -1)
📝 pkg/runner/job_executor.go (+4 -1)
📝 pkg/runner/logger.go (+23 -1)
📝 pkg/runner/run_context.go (+11 -4)
📝 pkg/runner/runner.go (+1 -0)
📝 pkg/runner/step_docker.go (+4 -1)

📄 Description

This PR introduces a new --focus (-f) flag, which, when enabled, will suppress all logs except those emitted by the processes inside the running container.

Doing so, reduces this:

act --job json
[Linting/json] 🚀  Start image=catthehacker/ubuntu:act-latest
[Linting/json]   🐳  docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true
[Linting/json]   🐳  docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[]
[Linting/json]   🐳  docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[]
[Linting/json] ⭐ Run Main actions/checkout@v3
[Linting/json]   🐳  docker cp src=... dst=...
[Linting/json]   ✅  Success - Main actions/checkout@v3
[Linting/json] ⭐ Run Main ./.github/actions/linters/json
[Linting/json]   ☁  git clone 'https://github.com/actionsx/prettier' # ref=v3
[Linting/json] ⭐ Run Main actionsx/prettier@v3
[Linting/json]   🐳  docker cp src=/Users/jean/.cache/act/actionsx-prettier@v3/ dst=/var/run/act/actions/actionsx-prettier@v3/
[Linting/json]   🐳  docker exec cmd=[node /var/run/act/actions/actionsx-prettier@v3/dist/index.js] user= workdir=
| Checking formatting...
| All matched files use Prettier code style!
[Linting/json]   ✅  Success - Main actionsx/prettier@v3
[Linting/json]   ✅  Success - Main ./.github/actions/linters/json
[Linting/json] ⭐ Run Post ./.github/actions/linters/json
[Linting/json]   ✅  Success - Post ./.github/actions/linters/json
[Linting/json] 🏁  Job succeeded

To this:

act --job json --focus
[Linting/json] Checking formatting...
[Linting/json] All matched files use Prettier code style!

The two differences are:

  • Non-process logs are only emitted if they are WARN or above.
  • Process logs have their workflow/job names prefixed, to distinguish multiple runners from each other.

For those who really only want the process logs without any annotations, you can add --json and then format the output using jq etc, e.g.:

act --job json --focus --json | jq -r '.msg | gsub("\\n"; "")'
Checking formatting...
All matched files use Prettier code style!

The implementation itself works, but isn't as elegant as I would like because I didn't want to introduce any backward breaking changes.

I think, ideally, with two separate loggers (one for the process messages, the other for messages from act itself), there would be flags to control the log level of each individual logger, and do away with --quiet, --focus, and --verbose.

But, the current implementation works for me and doesn't introduce any backward breaking changes, so I figured I'd push this up, either for you to modify, or take as is.


One other alternative that I only thought of as I was writing this PR description, is to introduce a new field on the JSON-based log output, to distinguish between process and act logs. That way, we could again use jq to filter out the logs we don't want. The downside is we'd lose the pretty printing niceties, so it's a trade-off of supporting this in the utility itself, or giving people the hooks to do it themselves outside the process.

Edit: one more thing I forgot to mention — I didn't add any tests yet. I'm uncertain if/where logging output is tested, so feel free to either add it yourself, or give me some pointers, so I can see if I can find some additional time to add them.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/nektos/act/pull/1945 **Author:** [@JeanMertz](https://github.com/JeanMertz) **Created:** 8/5/2023 **Status:** ❌ Closed **Base:** `master` ← **Head:** `jean/focus-mode` --- ### 📝 Commits (1) - [`819c0a6`](https://github.com/nektos/act/commit/819c0a642474f1c0daca8426786eb8480af2adef) feat: only print container logs with `--focus` ### 📊 Changes **11 files changed** (+78 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `cmd/input.go` (+1 -0) 📝 `cmd/root.go` (+7 -0) 📝 `pkg/common/logger.go` (+18 -0) 📝 `pkg/runner/action.go` (+4 -1) 📝 `pkg/runner/action_composite.go` (+4 -1) 📝 `pkg/runner/command.go` (+1 -1) 📝 `pkg/runner/job_executor.go` (+4 -1) 📝 `pkg/runner/logger.go` (+23 -1) 📝 `pkg/runner/run_context.go` (+11 -4) 📝 `pkg/runner/runner.go` (+1 -0) 📝 `pkg/runner/step_docker.go` (+4 -1) </details> ### 📄 Description This PR introduces a new `--focus` (`-f`) flag, which, when enabled, will suppress all logs _except_ those emitted by the processes inside the running container. Doing so, reduces this: ``` act --job json [Linting/json] 🚀 Start image=catthehacker/ubuntu:act-latest [Linting/json] 🐳 docker pull image=catthehacker/ubuntu:act-latest platform= username= forcePull=true [Linting/json] 🐳 docker create image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] [Linting/json] 🐳 docker run image=catthehacker/ubuntu:act-latest platform= entrypoint=["tail" "-f" "/dev/null"] cmd=[] [Linting/json] ⭐ Run Main actions/checkout@v3 [Linting/json] 🐳 docker cp src=... dst=... [Linting/json] ✅ Success - Main actions/checkout@v3 [Linting/json] ⭐ Run Main ./.github/actions/linters/json [Linting/json] ☁ git clone 'https://github.com/actionsx/prettier' # ref=v3 [Linting/json] ⭐ Run Main actionsx/prettier@v3 [Linting/json] 🐳 docker cp src=/Users/jean/.cache/act/actionsx-prettier@v3/ dst=/var/run/act/actions/actionsx-prettier@v3/ [Linting/json] 🐳 docker exec cmd=[node /var/run/act/actions/actionsx-prettier@v3/dist/index.js] user= workdir= | Checking formatting... | All matched files use Prettier code style! [Linting/json] ✅ Success - Main actionsx/prettier@v3 [Linting/json] ✅ Success - Main ./.github/actions/linters/json [Linting/json] ⭐ Run Post ./.github/actions/linters/json [Linting/json] ✅ Success - Post ./.github/actions/linters/json [Linting/json] 🏁 Job succeeded ``` To this: ``` act --job json --focus [Linting/json] Checking formatting... [Linting/json] All matched files use Prettier code style! ``` The two differences are: - Non-process logs are only emitted if they are `WARN` or above. - Process logs have their workflow/job names prefixed, to distinguish multiple runners from each other. For those who really _only_ want the process logs without any annotations, you can add `--json` and then format the output using `jq` etc, e.g.: ``` act --job json --focus --json | jq -r '.msg | gsub("\\n"; "")' Checking formatting... All matched files use Prettier code style! ``` The implementation itself works, but isn't as elegant as I would like because I didn't want to introduce any backward breaking changes. I think, ideally, with two separate loggers (one for the process messages, the other for messages from act itself), there would be flags to control the log level of each individual logger, and do away with `--quiet`, `--focus`, and `--verbose`. But, the current implementation works for me and doesn't introduce any backward breaking changes, so I figured I'd push this up, either for you to modify, or take as is. --- One other alternative that I only thought of as I was writing this PR description, is to introduce a new field on the JSON-based log output, to distinguish between process and act logs. That way, we could again use `jq` to filter out the logs we don't want. The downside is we'd lose the pretty printing niceties, so it's a trade-off of supporting this in the utility itself, or giving people the hooks to do it themselves outside the process. Edit: one more thing I forgot to mention — I didn't add any tests yet. I'm uncertain if/where logging output is tested, so feel free to either add it yourself, or give me some pointers, so I can see if I can find some additional time to add them. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-01 21:54:26 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/act#2203
No description provided.