Skip to content

Commit

Permalink
chore: rename ECS formatter to Elastic
Browse files Browse the repository at this point in the history
  • Loading branch information
Bart van Oort committed May 21, 2024
1 parent 8453d23 commit 90534df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule LoggerJSON.Formatters.ECS do
defmodule LoggerJSON.Formatters.Elastic do
@moduledoc """
Custom Erlang's [`:logger` formatter](https://www.erlang.org/doc/apps/kernel/logger_chapter.html#formatters) which
writes logs in a JSON-structured format that conforms to the Elastic Common Schema (ECS), so it can be consumed by
Expand All @@ -22,9 +22,9 @@ defmodule LoggerJSON.Formatters.ECS do
"@timestamp" => "2024-05-17T16:20:00.000Z",
"ecs.version" => "8.11.0",
"log.level" => "info",
"log.logger" => "Elixir.LoggerJSON.Formatters.ECSTest",
"log.logger" => "Elixir.LoggerJSON.Formatters.ElasticTest",
"log.origin" => %{
"file.name" => ~c"/app/logger_json/test/formatters/ecs_test.exs",
"file.name" => ~c"/app/logger_json/test/formatters/elastic_test.exs",
"file.line" => 18,
"function" => "test logs an LogEntry of every level/1"
},
Expand All @@ -40,10 +40,10 @@ defmodule LoggerJSON.Formatters.ECS do
"fiz" => %{"buz" => "buz"},
"foo" => "bar",
"log.level" => "debug",
"log.logger" => "Elixir.LoggerJSON.Formatters.ECSTest",
"log.logger" => "Elixir.LoggerJSON.Formatters.ElasticTest",
"log.origin" => %{
"file.line" => 68,
"file.name" => ~c"/app/logger_json/test/formatters/ecs_test.exs",
"file.name" => ~c"/app/logger_json/test/formatters/elastic_test.exs",
"function" => "test logs an LogEntry with a map payload containing message/1"},
"message" => "Hello"
}
Expand All @@ -54,7 +54,7 @@ defmodule LoggerJSON.Formatters.ECS do
"@timestamp" => "2024-05-17T16:20:00.000Z",
"ecs.version" => "8.11.0",
"error.message" => "runtime error",
"error.stack_trace" => "** (RuntimeError) runtime error\\n Elixir.LoggerJSON.Formatters.ECSTest.erl:159: anonymous fn/4 in LoggerJSON.Formatters.ECSTest.\\"test logs exceptions\\"/1\\n",
"error.stack_trace" => "** (RuntimeError) runtime error\\n Elixir.LoggerJSON.Formatters.ElasticTest.erl:159: anonymous fn/4 in LoggerJSON.Formatters.ElasticTest.\\"test logs exceptions\\"/1\\n",
"error.type" => "Elixir.RuntimeError",
"log.level" => "error",
"message" => "runtime error"
Expand All @@ -80,8 +80,8 @@ defmodule LoggerJSON.Formatters.ECS do
"error.code" => 42,
"error.id" => "oops_id",
"error.message" => "oops!",
"error.stack_trace" => "** (LoggerJSON.Formatters.ECSTest.TestException) oops!\n test/formatters/ecs_test.exs:190: anonymous fn/0 in LoggerJSON.Formatters.ECSTest.\"test logs exceptions with id and code\"/1\n",
"error.type" => "Elixir.LoggerJSON.Formatters.ECSTest.TestException",
"error.stack_trace" => "** (LoggerJSON.Formatters.ElasticTest.TestException) oops!\n test/formatters/elastic_test.exs:190: anonymous fn/0 in LoggerJSON.Formatters.ElasticTest.\"test logs exceptions with id and code\"/1\n",
"error.type" => "Elixir.LoggerJSON.Formatters.ElasticTest.TestException",
"log.level" => "error",
"message" => "oops!"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
defmodule LoggerJSON.Formatters.ECSTest do
defmodule LoggerJSON.Formatters.ElasticTest do
use LoggerJSON.Case
use ExUnitProperties
alias LoggerJSON.Formatters.ECS
alias LoggerJSON.Formatters.Elastic
require Logger

setup do
formatter = {ECS, metadata: :all}
formatter = {Elastic, metadata: :all}
:logger.update_handler_config(:default, :formatter, formatter)
end

Expand All @@ -25,7 +25,7 @@ defmodule LoggerJSON.Formatters.ECSTest do
"@timestamp" => timestamp,
"ecs.version" => "8.11.0",
"log.level" => ^level_string,
"log.logger" => "Elixir.LoggerJSON.Formatters.ECSTest",
"log.logger" => "Elixir.LoggerJSON.Formatters.ElasticTest",
"log.origin" => %{
"file.name" => origin_file,
"file.line" => origin_line,
Expand All @@ -36,7 +36,7 @@ defmodule LoggerJSON.Formatters.ECSTest do

assert {:ok, _, _} = DateTime.from_iso8601(timestamp)
assert origin_line > 0
assert String.ends_with?(to_string(origin_file), "test/logger_json/formatters/ecs_test.exs")
assert String.ends_with?(to_string(origin_file), "test/logger_json/formatters/elastic_test.exs")
assert String.starts_with?(to_string(origin_function), "test logs message of every level/1")
assert log_entry["domain"] == nil
end
Expand Down Expand Up @@ -205,8 +205,8 @@ defmodule LoggerJSON.Formatters.ECSTest do
} = log_entry

assert stacktrace =~ "** (RuntimeError) runtime error"
assert stacktrace =~ ~r/test\/logger_json\/formatters\/ecs_test.exs:\d+: anonymous fn\/0/
assert stacktrace =~ "in LoggerJSON.Formatters.ECSTest.\"test logs exceptions\"/1"
assert stacktrace =~ ~r/test\/logger_json\/formatters\/elastic_test.exs:\d+: anonymous fn\/0/
assert stacktrace =~ "in LoggerJSON.Formatters.ElasticTest.\"test logs exceptions\"/1"
assert log_entry["error_logger"] == nil
end

Expand All @@ -232,7 +232,7 @@ defmodule LoggerJSON.Formatters.ECSTest do
"message" => "oops!",
"error.message" => "oops!",
"error.stack_trace" => _,
"error.type" => "Elixir.LoggerJSON.Formatters.ECSTest.TestException",
"error.type" => "Elixir.LoggerJSON.Formatters.ElasticTest.TestException",
"error.id" => "oops_id",
"error.code" => 42
} = log_entry
Expand Down Expand Up @@ -276,7 +276,7 @@ defmodule LoggerJSON.Formatters.ECSTest do
"error.message" => "throw: {:error, :whatever}",
"error.stack_trace" => "** (throw) {:error, :whatever}",
"error.type" => "throw",
"log.logger" => "Elixir.LoggerJSON.Formatters.ECSTest",
"log.logger" => "Elixir.LoggerJSON.Formatters.ElasticTest",
"log.origin" => %{
"file.line" => _,
"file.name" => _,
Expand All @@ -299,7 +299,7 @@ defmodule LoggerJSON.Formatters.ECSTest do
"error.message" => "exit: :sad_failure",
"error.stack_trace" => "** (exit) :sad_failure",
"error.type" => "exit",
"log.logger" => "Elixir.LoggerJSON.Formatters.ECSTest",
"log.logger" => "Elixir.LoggerJSON.Formatters.ElasticTest",
"log.origin" => %{
"file.line" => _,
"file.name" => _,
Expand All @@ -322,7 +322,7 @@ defmodule LoggerJSON.Formatters.ECSTest do
"error.message" => error_message,
"error.stack_trace" => stacktrace,
"error.type" => "EXIT",
"log.logger" => "Elixir.LoggerJSON.Formatters.ECSTest",
"log.logger" => "Elixir.LoggerJSON.Formatters.ElasticTest",
"log.origin" => %{
"file.line" => _,
"file.name" => _,
Expand All @@ -348,7 +348,7 @@ defmodule LoggerJSON.Formatters.ECSTest do
"error.message" => "socket_closed_unexpectedly: []",
"error.stack_trace" => "** (socket_closed_unexpectedly) []",
"error.type" => "socket_closed_unexpectedly",
"log.logger" => "Elixir.LoggerJSON.Formatters.ECSTest",
"log.logger" => "Elixir.LoggerJSON.Formatters.ElasticTest",
"log.origin" => %{
"file.line" => _,
"file.name" => _,
Expand Down

0 comments on commit 90534df

Please sign in to comment.