diff --git a/lib/logger_json/formatters/ecs.ex b/lib/logger_json/formatters/elastic.ex similarity index 91% rename from lib/logger_json/formatters/ecs.ex rename to lib/logger_json/formatters/elastic.ex index 64005b2..15e9f2e 100644 --- a/lib/logger_json/formatters/ecs.ex +++ b/lib/logger_json/formatters/elastic.ex @@ -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 @@ -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" }, @@ -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" } @@ -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" @@ -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!" } diff --git a/test/logger_json/formatters/ecs_test.exs b/test/logger_json/formatters/elastic_test.exs similarity index 93% rename from test/logger_json/formatters/ecs_test.exs rename to test/logger_json/formatters/elastic_test.exs index 633486c..2c7bc6e 100644 --- a/test/logger_json/formatters/ecs_test.exs +++ b/test/logger_json/formatters/elastic_test.exs @@ -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 @@ -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, @@ -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 @@ -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 @@ -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 @@ -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" => _, @@ -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" => _, @@ -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" => _, @@ -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" => _,