Disable Elixir Ecto Debug output

蹲街弑〆低调 提交于 2019-12-03 10:05:48

Your logging level is configured in your config/#{env}.exs files. If you look into config/prod.exs it most likely already has that level set to :info:

config :logger, level: :info

So if you run the app with MIX_ENV=prod iex -S mix you won't get the debug output. This means that when you build a release with something like MIX_ENV=prod mix release the resulting build won't be producing this output. Alternatively you may set level: :info or :warn for whatever environment you want by changing the appropriate config/#{env}.exs.

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.

Simple put loggers: [] in

config :my_app, MyApp.Repo, adapter: Ecto.Adapters.Postgres, database: "my_app_repo", username: "DB_USERNAME", password: "DB_PASSWORD", hostname: "DB_HOST", loggers: []

Ecto 3 answer to completely disabling logging would be:

config :app, App.Repo,
  username: "postgres",
  password: "postgres",
  database: "app_dev",
  log: false

To disable debug messages temporarily you can do Logger.configure(level: :warn) and then re-enable with Logger.configure(level: :debug).

https://hexdocs.pm/logger/Logger.html#Levels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!