Skip to content

Commit

Permalink
🐛 Fix milliseconds precision in log messages (#30)
Browse files Browse the repository at this point in the history
The `NaiveDateTime.new/1` expects microseconds, not
milliseconds. Multiplying by 1000 fixes the problem.
  • Loading branch information
ulissesalmeida authored and svetob committed Jun 12, 2019
1 parent a947837 commit 9f80261
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/logstash_json/event.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ defmodule LogstashJson.Event do
end

defp datetime({{year, month, day}, {hour, min, sec, millis}}) do
{:ok, ndt} = NaiveDateTime.new(year, month, day, hour, min, sec, {millis, 3})
{:ok, ndt} = NaiveDateTime.new(year, month, day, hour, min, sec, {millis * 1000, 3})
NaiveDateTime.to_iso8601(ndt)
end

Expand Down
2 changes: 1 addition & 1 deletion test/event_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule EventTest do

assert Map.get(event, :message) == message
assert Map.get(event, :level) == :info
assert String.starts_with?(time, "2015-04-19T08:15:03.000")
assert String.starts_with?(time, "2015-04-19T08:15:03.028")
assert String.length(time) == 29
end

Expand Down

0 comments on commit 9f80261

Please sign in to comment.