Skip to content

Commit e363887

Browse files
committed
Fix inconsistency with formatter_opts type
1 parent cc8d932 commit e363887

File tree

4 files changed

+7
-6
lines changed

4 files changed

+7
-6
lines changed

lib/logger_json.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ defmodule LoggerJSON do
204204
|> Keyword.get(:metadata, [])
205205
|> configure_metadata()
206206

207-
formatter_opts = Keyword.get(config, :formatter_opts, %{})
208-
formatter_state = apply(formatter, :init, [formatter_opts])
207+
formatter_opts = Keyword.get(config, :formatter_opts, [])
208+
formatter_state = formatter.init(formatter_opts)
209209

210210
%{
211211
state

lib/logger_json/formatter.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule LoggerJSON.Formatter do
1111
1212
Returned list will be used as formatter_state in `format_event/6`.
1313
"""
14-
@callback init(Keyword.t()) :: Keyword.t()
14+
@callback init(Keyword.t()) :: term()
1515

1616
@doc """
1717
Format event callback.

lib/logger_json/formatters/datadog_logger.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ defmodule LoggerJSON.Formatters.DatadogLogger do
3232
@processed_metadata_keys ~w[pid file line function module application span_id trace_id otel_span_id otel_trace_id]a
3333

3434
@impl true
35-
def init(formatter_opts \\ %{}) do
36-
opts = Map.merge(@default_opts, formatter_opts)
35+
def init(formatter_opts) do
36+
# Notice: we also accept formatter_opts for DataDog logger as a map for backwards compatibility
37+
opts = Map.merge(@default_opts, Map.new(formatter_opts))
3738

3839
unless is_binary(opts.hostname) or opts.hostname in [:system, :unset] do
3940
raise ArgumentError,

mix.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ defmodule LoggerJSON.Mixfile do
22
use Mix.Project
33

44
@source_url "https://github.com/Nebo15/logger_json"
5-
@version "5.1.1"
5+
@version "5.1.2"
66

77
def project do
88
[

0 commit comments

Comments
 (0)