During mix test, is there a way to see logs from tested app, e.g. controller?

I can see Logger outputs from my test scripts, but when I add Logger statements into the tested application, these won’t show during the mix test run. Is there a way to save or view Logger outputs from within the tested application ?

Just change the line:

config :logger, level: :warn


config :logger, level: :debug

On your config/test.exs file.


I’ve done this, and see the Logger.debug data from any script in the test section, but what I would like to also see is the Logger.debug info from within the application, and I cannot see these. The console shows what is happening on the test side, not the app side.

Are you sure this application code you have gets executed? You can use IO.puts to check that, since it is not disabled by the mentioned config.

I’m sure it gets executed, my Logger statement is in the controller’s show function and gets called multiple times. My understanding of the problem I face is that when you test, you’re running two things, one client app for testing, and one server app (the phoenix app). And the console I’m watching is the test side/client. I’m pretty new to Elixir so might be completely wrong in my understanding of how this runs. All I can see is that only test side logger lines are showing in the console.

Well, actually Logger is an app itself, which all other apps send messages to it when they want to log something to the Logger output, which by default is your stdio. So there should be no difference calling Logger.debug from inside two different apps.


I assumed controller show was called because my controller test is calling get. But after putting a custom logger plug within my router file, I realize the show function is not reached. I get redirected before reaching it. Thanks for your help.

1 Like