Skip to content

Commit 92eb759

Browse files
committed
feat: use erlang time metadata
1 parent 84c277f commit 92eb759

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/metadata_logger.ex

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ defmodule MetadataLogger do
179179
def log_to_map(level, message, ts, metadata) do
180180
m = Enum.into(metadata, %{})
181181
{level, m} = Map.pop(m, :erl_level, level)
182+
{time, m} = Map.pop(m, :time)
182183

183184
with m <- Map.drop(m, [:error_logger, :mfa, :report_cb]),
184185
{app, m} <- Map.pop(m, :application),
@@ -211,7 +212,7 @@ defmodule MetadataLogger do
211212
end
212213
|> Map.put(:level, level)
213214
|> Map.put(:message, transform_message(message))
214-
|> Map.put(:timestamp, transform_timestamp(ts))
215+
|> Map.put(:timestamp, transform_timestamp(time, ts))
215216
end
216217

217218
defp nil_or_inspect(nil), do: nil
@@ -229,11 +230,15 @@ defmodule MetadataLogger do
229230
defp transform_message(m) when is_list(m), do: IO.iodata_to_binary(m)
230231
defp transform_message(m), do: to_string(m)
231232

232-
defp transform_timestamp({{y, month, d}, {h, minutes, s, mil}}) do
233+
defp transform_timestamp(nil, {{y, month, d}, {h, minutes, s, mil}}) do
233234
{:ok, dt} = NaiveDateTime.new(y, month, d, h, minutes, s, mil)
234235
dt
235236
end
236237

238+
defp transform_timestamp(time_ms, _) do
239+
DateTime.from_unix!(time_ms, :microsecond)
240+
end
241+
237242
defp scrub(map) do
238243
map
239244
|> Map.delete(:function)

0 commit comments

Comments
 (0)