【问题标题】:How to avoid ecto logs inside iex?如何避免iex内的ecto日志?
【发布时间】:2016-11-06 20:42:16
【问题描述】:

我有一个创建数据库查询的工作人员,如下所示:

defmodule MyApp.Periodically do
  use GenServer

  def start_link do
    GenServer.start_link(__MODULE__, %{})
  end

  def init(state) do
    schedule_work() # Schedule work to be performed at some point
    {:ok, state}
  end

  def handle_info(:work, state) do
    # big amount of ecto stuff
    schedule_work() # Reschedule once more
    {:noreply, state}
  end

  defp schedule_work() do
    Process.send_after(self(), :work, 2 * 60 * 60 * 1000) # In 2 hours
  end
end

除了一件事,一切都很好。当我打开 iex -S mix 时,我的 shell 中收到了很多 ecto debug 消息,例如:

01:58:10.921 [debug] QUERY OK db=7.8ms decode=0.2ms
SELECT r0."id", r0."description", r0."property_type", r0."beds", r0."baths", r0."square", r0."price", r0."availability", r0."state", r0."country", r0."city", r0."address", r0."zipcode", r0."full_address", r0."external_provider_url", r0."location", r0."visits_count", r0."likes_count", r0."comments_count", r0."deleted_at", r0."credits", r0."somehere", r0."zis", r0."thumbnail_type", r0."video", r0."review_thumbnail", r0."user_id", r0."inserted_at", r0."updated_at" FROM "reviews" AS r0 WHERE (r0."zis" IS NULL AND r0."somehere" IS NULL) ORDER BY r0."id" LIMIT 1 []

我怎样才能避免这种情况?

【问题讨论】:

    标签: elixir elixir-iex


    【解决方案1】:

    您可以更改您的日志级别(在 iex 中):

    Logger.configure(level: :info)
    

    或者在你的配置中:

    config :logger, level: :info
    

    您可以完全禁用 Ecto 的日志:

    config :my_app, MyApp.Repo,
      loggers: []
    

    https://hexdocs.pm/ecto/Ecto.Repo.html中所述

    【讨论】:

      猜你喜欢
      • 2014-12-12
      • 2023-01-12
      • 2015-09-09
      • 2015-04-12
      • 2010-12-22
      • 1970-01-01
      • 1970-01-01
      • 2010-11-04
      • 2016-10-02
      相关资源
      最近更新 更多