Just tried my own advice and this unfortunately won’t work!
Docs say that
:function
- purges all messages with the “function/arity” Remember that if you want to purge log calls from a dependency, the dependency must be recompiled.
So I first modified my logger config to find the logging function:
config :logger, :console,
format: "$time\n[$level] $metadata\n$message\n\n",
metadata: [:mfa, :file, :line]
That resulted in
[debug] mfa=Ecto.Adapters.SQL.log/4 file=lib/ecto/adapters/sql.ex line=938
QUERY OK …
But the ecto_sql
library at line 938 invokes Logger.log/3 which warns that
The macros debug/2
, info/2
, notice/2
, warning/2
, error/2
, critical/2
, alert/2
, and emergency/2
are preferred over this macro as they can automatically eliminate the call to Logger
altogether at compile time if desired (see the documentation for the Logger
module).
I added an explicit :debug
case option to the log/4
source code in my deps folder and recompiled as instructed with mix deps.compile ecto_sql
but it’s still logging?
:debug ->
IO.puts("SQL debug")
Logger.debug(
fn -> log_iodata(measurements, metadata) end,
ansi_color: sql_color(query_string)
)
config.exs
config :logger, :console,
format: "$time\n[$level] $metadata\n$message\n\n",
metadata: [:mfa, :file, :line],
compile_time_purge_matching: [
[module: Ecto.Adapters.SQL, function: "log/4", level_lower_than: :info]
]
iex(1)> Repo.all(User)
SQL debug
14:02:05.547
[debug] mfa=Ecto.Adapters.SQL.log/4 file=lib/ecto/adapters/sql.ex line=939
QUERY OK source="users" ...
Hopefully someone with more experience can provide some insight