Skip to content

Commit

Permalink
employ Useful.stringify_map/1 in Auth.Log.stringify/1 instead of repe…
Browse files Browse the repository at this point in the history
…ating the defintion! #230 (comment)
  • Loading branch information
nelsonic committed Oct 17, 2022
1 parent b383ce0 commit 80e7671
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions lib/auth/log.ex
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,11 @@ defmodule Auth.Log do

def stringify(map) when is_map(map) do
map
# remove any metadata from Ecto or Structs:
|> Map.delete(:__meta__)
|> Map.delete(:__struct__)
# avoid leaking personal data (person.email) in logs
|> Map.delete(:email)
|> Useful.flatten_map()
|> Map.keys()
|> Enum.map(fn key ->
unless is_nil(Map.get(map, key)) do
"#{key}:#{Map.get(map, key)}"
end
end)
# Remove nil values
|> Enum.filter(&(!is_nil(&1)))
|> Enum.join(", ")
end

def stringify(map) when is_nil(map) do
"nil"
|> Useful.stringify_map()
end
end

0 comments on commit 80e7671

Please sign in to comment.