This repository was archived by the owner on Dec 8, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed
test/lib/timber/integrations Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ defmodule Timber.Integrations.EctoLogger do
8080 which is then logged at the designated level.
8181 """
8282 @ spec log ( Ecto.LogEntry . t ) :: Ecto.LogEntry . t
83- def log ( % { query: query , query_time: time_native } = entry , level ) do
83+ def log ( % { query: query , query_time: time_native } = entry , level ) when is_integer ( time_native ) do
8484 case resolve_query ( query , entry ) do
8585 { :ok , query_text } ->
8686 # The time is given in native units which the VM determines. We have
@@ -107,6 +107,13 @@ defmodule Timber.Integrations.EctoLogger do
107107 end
108108 end
109109
110+ # time_native above is not an integer as expected. This is required and a violation of the
111+ # type spec. Queries of this nature will be ignored.
112+ def log ( entry , _level ) do
113+ entry
114+ end
115+
116+
110117 # Interestingly, the query is not necessarily a String.t, it
111118 # can also be a single-arity function which, given the log entry
112119 # as a parameter, will return a String.t
Original file line number Diff line number Diff line change @@ -20,6 +20,16 @@ if Code.ensure_loaded?(Ecto) do
2020 assert log =~ "Processed SELECT * FROM table in"
2121 assert log =~ " @metadata "
2222 end
23+
24+ test "query_time is nil" do
25+ query = "SELECT * FROM table"
26+
27+ log = capture_log ( fn ->
28+ EctoLogger . log ( % { query: query , query_time: nil } , :info )
29+ end )
30+
31+ assert log == ""
32+ end
2333 end
2434 end
2535end
You can’t perform that action at this time.
0 commit comments