Disable Elixir Ecto Debug output

王志軍 picture 王志軍 · May 18, 2015 · Viewed 9.4k times · Source

Whatever in iex> or using mix run -e "My.code" when I run the mix project using ecto, the Ecto's Debugging Mechanism display a bunch of SQLs like below

16:42:12.870 [debug] SELECT a0.`id` FROM `account` AS a0 WHERE (a0.`account_name` = ?) ["71000000313"] (39.6ms)`
...

When I dont need the debug output anymore, How can I turn it off, I cannot find anything about how to change ecto log level stuff.

Thanks in advance.

Answer

Szymon Jeż picture Szymon Jeż · May 19, 2015

If you want to change the Ecto (pre 2.0) log level (and only it) then you can use the log_level configuration option that can be set in your applications Ecto repository configuration. In example:

config :my_app, MyApp.Repo,
  adapter: Ecto.Adapters.Postgres,
  database: "my_app",
  username: "my_app",
  password: "secret",
  hostname: "localhost",
  port: 5433,
  log_level: :info

Of course beside the above you can always change the Logger configuration log level option if you want to change the overall log level (not only the Ecto log level) e.g.:

config :logger, level: :info

Update (by @Milos):

Since Ecto 2.0.0, instead of log_level: :info you need to use loggers: [{Ecto.LogEntry, :log, [:info]}].

Update (by @AndyMacKinlay):

Since Ecto 3.0.0, instead of log_level: :info you need to use log: :info.