Skip to content

Instantly share code, notes, and snippets.

@jeregrine
Created June 5, 2015 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeregrine/5f45c2491840e6a7e868 to your computer and use it in GitHub Desktop.
Save jeregrine/5f45c2491840e6a7e868 to your computer and use it in GitHub Desktop.
ecto repo logging
defmodule MyApp.Repo do
use Ecto.Repo, otp_app: :my_app
def log(entry) do
Logger.info(fn ->
[log_time("measure#database.query", entry.query_time, true), log_time("measure#database.queue", entry.queue_time, false)]
end)
super(entry)
end
defp log_time(_label, nil, _force), do: []
defp log_time(label, time, force) do
ms = div(time, 100) / 10
if force or ms > 0 do
[?\s, label, ?=, :io_lib_format.fwrite_g(ms), ?m, ?s]
else
[]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment