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

How to handle logs interleaving with Hurl progress bar #3296

Open
Thomasdezeeuw opened this issue Oct 9, 2024 · 2 comments
Open

How to handle logs interleaving with Hurl progress bar #3296

Thomasdezeeuw opened this issue Oct 9, 2024 · 2 comments

Comments

@Thomasdezeeuw
Copy link

Current Hurl overwrites the previous line when it writes its progress bar (relevant code here:

// We count the number of new lines \n. We can't use the `String::lines()` because
// it counts a line for a single carriage return. We don't want to go up for a
// single carriage return.
let lines = self.progress_bar.chars().filter(|c| *c == '\n').count();
// We used the following ANSI codes:
// - K: "EL - Erase in Line" sequence. It clears from the cursor to the end of line.
// - 1A: "Cursor Up". Up to one line
// <https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_sequences>
if lines > 0 {
(0..lines).for_each(|_| eprint!("\x1B[1A\x1B[K"));
} else {
eprint!("\x1B[K");
}
). This allows it to "progress" the progress bar.

The problems comes when another process logs to the same output.

We use Hurl for our testing (which is great btw -- well done!), but it will overwrite any of the application log which we log to standard out/error by default. Currently we work around this by logging our service logs to a separate file and hope we don't have to look at :) (i.e. no errors happen). But this is less than ideal.

Are there any better solutions for this?

@jcamiel
Copy link
Collaborator

jcamiel commented Oct 9, 2024

Hi @Thomasdezeeuw

With --test, there is currently no explicit way of disabling progress bar. As a workaround, you can either pipe Hurl's stderr to a file (that will disable progress bar), or declare an env var "CI" that will also disable progress bar to be drawn. That said, we plan to add an explicit --progress-bar option to force display of progress bar, we can also add a --no-progress-bar to explicitly disable it.

@Thomasdezeeuw
Copy link
Author

Thomasdezeeuw commented Oct 14, 2024

Thanks for the response @jcamiel. It's not so much about disabling the progress bar, although that would solve the issue, it's more about it not overwriting the log output.

For a bit more context, when running our tests we expect zero logs from our services as we only log errors. But if a test does fail the log from our service is now (partially) overwritten. The progress bar is quite useful when actively working on the code & running the tests in parallel.

So basically I'm asking for "don't overwrite if another process wrote the previous output", which I don't think is possible. I was wondering if anyone found a better work around than logging to a separate file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants