Skip to content

Commit

Permalink
Fix inconsistency with formatter_opts type
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewDryga committed Oct 19, 2022
1 parent cc8d932 commit e363887
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/logger_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,8 @@ defmodule LoggerJSON do
|> Keyword.get(:metadata, [])
|> configure_metadata()

formatter_opts = Keyword.get(config, :formatter_opts, %{})
formatter_state = apply(formatter, :init, [formatter_opts])
formatter_opts = Keyword.get(config, :formatter_opts, [])
formatter_state = formatter.init(formatter_opts)

%{
state
Expand Down
2 changes: 1 addition & 1 deletion lib/logger_json/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ defmodule LoggerJSON.Formatter do
Returned list will be used as formatter_state in `format_event/6`.
"""
@callback init(Keyword.t()) :: Keyword.t()
@callback init(Keyword.t()) :: term()

@doc """
Format event callback.
Expand Down
5 changes: 3 additions & 2 deletions lib/logger_json/formatters/datadog_logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ defmodule LoggerJSON.Formatters.DatadogLogger do
@processed_metadata_keys ~w[pid file line function module application span_id trace_id otel_span_id otel_trace_id]a

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

unless is_binary(opts.hostname) or opts.hostname in [:system, :unset] do
raise ArgumentError,
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ defmodule LoggerJSON.Mixfile do
use Mix.Project

@source_url "https://github.com/Nebo15/logger_json"
@version "5.1.1"
@version "5.1.2"

def project do
[
Expand Down

0 comments on commit e363887

Please sign in to comment.