Created
June 5, 2015 14:37
ecto repo logging
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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