Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: only print container logs with --focus #1945

Closed
wants to merge 1 commit into from

Conversation

JeanMertz
Copy link

@JeanMertz JeanMertz commented Aug 5, 2023

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.

@JeanMertz JeanMertz requested a review from a team as a code owner August 5, 2023 06:47
@mergify
Copy link
Contributor

mergify bot commented Aug 8, 2023

@JeanMertz this pull request has failed checks πŸ› 

@mergify mergify bot added the needs-work Extra attention is needed label Aug 8, 2023
@mergify
Copy link
Contributor

mergify bot commented Oct 23, 2023

@JeanMertz this pull request is now in conflict 😩

@mergify mergify bot added the conflict PR has conflicts label Oct 23, 2023
Copy link
Contributor

PR is stale and will be closed in 14 days unless there is new activity

@github-actions github-actions bot added the stale label Apr 21, 2024
@github-actions github-actions bot closed this May 5, 2024
@mergify mergify bot removed the conflict PR has conflicts label May 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-work Extra attention is needed size/M stale
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant