Skip to content

Commit

Permalink
Ignore additional fields in data["fields"]
Browse files Browse the repository at this point in the history
  • Loading branch information
curiousleo committed Jan 20, 2016
1 parent b7e2e6c commit e5a4622
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions test/logger_logstash_backend_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ defmodule LoggerLogstashBackendTest do
Logger.info "hello world", [key1: "field1"]
json = get_log
{:ok, data} = JSX.decode json
me = inspect self
assert data["type"] === "some_app"
assert data["message"] === "hello world"
assert data["fields"] === %{
expected = %{
"function" => "test can log/1",
"level" => "info",
"module" => "Elixir.LoggerLogstashBackendTest",
"pid" => me,
"pid" => (inspect self),
"some_metadata" => "go here",
"line" => 42,
"key1" => "field1"
}
assert contains?(data["fields"], expected)
{:ok, ts} = DateFormat.parse data["@timestamp"], "%FT%T%z", :strftime
ts = Date.to_secs ts

Expand All @@ -73,4 +73,10 @@ defmodule LoggerLogstashBackendTest do
after 500 -> :nothing_received
end
end

defp contains?(map1, map2) do
Enum.all?(Map.to_list(map2), fn {key, value} ->
Map.fetch!(map1, key) == value
end)
end
end

0 comments on commit e5a4622

Please sign in to comment.