nextest-rs/nextest

How to prettify json logs?

xKeiro opened this issue · 2 comments

Prettifying json logs works when I run cargo test | bunyan but it does nothing when trying to use nextest. cargo nextest run | bunyan. How is it possible to prettify the logs when using nextest?

Thanks for the report! If I understand it correctly:

  • you have some tests run by cargo test
  • those tests produce JSON log lines to standard out (not standard error)
  • those log lines are printed by cargo test on failure, to standard out
  • then, bunyan can be used to format those lines

The biggest difference with nextest here is that nextest produces its outputs (both stdout and stderr) to standard error. (This is really the right behavior -- log-like outputs should generally go to stderr, not stdout).

So what you'll want to do is redirect stderr to stdout before piping it. This should work on all Unix shells:

cargo nextest run 2>&1 | bunyan

or, in bash and zsh:

cargo nextest run |& bunyan

Going to close this issue since I think it's answered -- feel free to reopen if you still run into issues!