air icon indicating copy to clipboard operation
air copied to clipboard

Allow output logging from fmt or log packages when executable is running.

Open c9845 opened this issue 2 years ago • 9 comments

As noted in issue #50, output logging only shows up when air is closed. This is a bit annoying since you have to close air (and most likely restart it) to see any log messages. This change fixes the output to occur while air is running and thus mirrors the functionality in fresh. I am unsure of any unintended side-effects of this change, but I have not noticed any thus far.

It looks like this bug/unintended functionality/whatever-you-want-to-call-it is caused by the wrapping of the io.Copy() calls for stdout and stderr into one goroutine and using with the cmd.Process.Wait() call. The Wait() call hangs/blocks endlessly until the binary (i.e. air) is closed/stopped thus not allowing the copying of the stdout or stderr to the terminal you ran air in. However, just removing the Wait() call did not allow logging to work; the Copy() calls had to be split into separate goroutines as well. Thus, at the end of the day, the code to fix this is simply a copying of the code from fresh.

References:

  • fresh lines https://github.com/gravityblast/fresh/blob/master/runner/runner.go#L28-L29.
  • air lines https://github.com/cosmtrek/air/blob/6f18a44eb4aa1eac4956755d7efc3605fc42f2ac/runner/engine.go#L434-L437

c9845 avatar Jul 07 '22 16:07 c9845

Codecov Report

Merging #306 (922f5d2) into master (6f18a44) will increase coverage by 1.45%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #306      +/-   ##
==========================================
+ Coverage   66.91%   68.36%   +1.45%     
==========================================
  Files           7        6       -1     
  Lines         943      942       -1     
==========================================
+ Hits          631      644      +13     
+ Misses        246      227      -19     
- Partials       66       71       +5     
Impacted Files Coverage Δ
runner/engine.go 63.08% <100.00%> (+0.78%) :arrow_up:
runner/util_linux.go
runner/util.go 70.37% <0.00%> (+0.82%) :arrow_up:
runner/config.go 75.11% <0.00%> (+5.11%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 6f18a44...922f5d2. Read the comment docs.

codecov[bot] avatar Jul 07 '22 18:07 codecov[bot]

pipeline timeout

xiantang avatar Jul 13 '22 02:07 xiantang

pipeline timeout

seems cannot use Ctrl+C to stop air

xiantang avatar Jul 13 '22 02:07 xiantang

Huh.... I build the binary and have used it on Windows and Ubuntu and can CTRL + C to exit without any issues on both systems. Looks like the checks related to Ubuntu specifically. The only issue I see is when you CTRL + C right after building... logs out there can be a bit of latency when deleting ..../tmp.

c9845 avatar Jul 13 '22 18:07 c9845

Huh.... I build the binary and have used it on Windows and Ubuntu and can CTRL + C to exit without any issues on both systems. Looks like the checks related to Ubuntu specifically. The only issue I see is when you CTRL + C right after building... logs out there can be a bit of latency when deleting ..../tmp.

Could you run all tests in ubuntu? It seems the test has been hung up for a long time. We did not meet this problem before.

xiantang avatar Jul 14 '22 14:07 xiantang

I have tried to rerun the failed test 3 times but still, have a hang-up issue. Maybe have something wrong in the code, after fixing this failed case I will merge the code because we need to keep the behavior of our program.

Thank you very much!

xiantang avatar Jul 14 '22 14:07 xiantang

I ran the tests on Ubuntu via the same commands as the Action and it completed successfully. I do not get the same "ERROR" lines as noted in the builder.

The build action is also throwing some strange Error: ./main.go:6:2: undefined: Println errors which make no sense to me.

I have attached the output of go test and the coverage.txt file for your inspection. Please let me know what you think.

air-test-output.txt coverage.txt

c9845 avatar Jul 14 '22 15:07 c9845

Ubuntu 18.04 LTS Go 1.18.4

c9845 avatar Jul 14 '22 15:07 c9845

Don't need to care about Error: ./main.go:6:2: undefined: Println because in the test we have triggered a build error intentionally. But when GitHub action parses the log, mark as build failed wrongly.

xiantang avatar Jul 14 '22 15:07 xiantang

Really looking forward to this PR being merged, or at least a build of it available somewhere I can use?

Flashy78 avatar Sep 21 '22 18:09 Flashy78

@Flashy78 not sure if this will be accepted since the integration tests fail for some unknown reason (they don't fail when I run them locally).

Shameless plug, I lost interest in this project and instead did a near-complete rewrite of fresh (which air is based upon) to add features and improve performance. github.com/c9845/fresher

c9845 avatar Sep 21 '22 19:09 c9845