For debugging purposes during a failing integration test, I would like to still be able to see my application logs. Is there a command I can pass to the mix test
task to accomplish this?
Every mix project has a config.exs
file. When mix starts, it loads this file. A common pattern in elixir is to define configs for different environments, like test.exs
, dev.exs
, prod.exs
, etc, etc.
Many projects like Phoenix will generate these files for you in your config
folder, and you'll see this line in your config.exs
line:
import_config "#{Mix.env}.exs"
When you run mix test
it sets MIX_ENV
environment variable to "test" which means the import_config line loads your test.exs
file.
So in order to set your logging level for just your tests, in your test.exs
file you can write the following:
# Print only warnings and errors during test
config :logger, level: :warn