slouchpie

slouchpie

ExUnit wish - retrospective `:test` env logger level

In :test env I have the usual logger config :point_down:

# Print only warnings and errors during test
config :logger, level: :warning

which means I have a nice clean console if everything passes (and I use capture_log and with_log when necessary).

Something I would very much enjoy is if I could somehow get the :info logs for failed tests only.

It has to be possible, right? Maybe some kind of custom logger that holds the :info logs in memory and only prints them if current test fails?

If it is possible, it would be really nice to be able to write logger config like this:

My wish :point_down:

config :logger, level: [passed: :warning, failed: :info]

First Post! Switch mode

arcanemachine

arcanemachine

Here’s how I have my config/test.exs set up:

config :logger, level: System.get_env("LOG_LEVEL", "warning") |> String.to_existing_atom()

Using this, you could run mix test to get the standard warning/error logs, then you could run LOG_LEVEL=info mix test --failed to get more detailed logs for your failed tests (could also use --trace to make it easier to tell which logs apply to which tests, perhaps).

It’s not quite what you’re asking for, but could get you something close to the desired results with very little work involved.

Most Liked

LostKobrakai

LostKobrakai

I usually put a Logger.configure(level: level) in the test in question.

slouchpie

slouchpie

These are useful and good techniques.

However, my wish is for a 0-effort solution that will also catch, say, a “flakey” test that fails sometimes and only when run as part of an entire async test suite. I do not want to have to manually change the log level and re-run tests. I want…magic!

LostKobrakai

LostKobrakai

You could generally enable logs and use ExUnit.Case — ExUnit v1.20.2 to show them only in case of errors.

There is however no magic after the fact getting access to already dropped logs.

Last Post!

garrison

garrison

Only marginally on topic here but this is one of the beautiful things about tests which are completely deterministic. When designed correctly you can retroactively re-enable (sometimes expensive) logging without changing the result. Obviously this is difficult to implement in practice, and not always possible :slight_smile:

Where Next?

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2976 91332 914
New
byu
@chrismccord : I just saw the Extract AGENTS.md from Phoenix.new into phx.new generator commit to the phoenix project. My initial shotgu...
New
arcanemachine
I was working on an Ecto migration and I needed a timestamp. So, for the nth time, I looked up the different data types for timestamps, a...
New
AstonJ
Just a general thread to post chat/news/info relating to AI/ML stuff that may be relevant for Nx now or in the future. Got anything to sh...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New
matt-savvy
Is there a word for the ~> symbol used in Version strings? Do you also just call it a Squiggle Arrow™ ?!
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New
zachdaniel
Introducing AshStorage! Attachment and file management that slots directly into your resources :smiling_face_with_sunglasses: I had hope...
New

We're in Beta

About us Mission Statement