Skip to content

Commit

Permalink
Use keyword list in Logger.Backend
Browse files Browse the repository at this point in the history
Instead of taking a string as the log group, take a keyword list with a
single key, for possible extension later.
  • Loading branch information
jeffkreeftmeijer committed Mar 6, 2023
1 parent 68961ac commit c48cc0b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions lib/appsignal/logger/backend.ex
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
defmodule Appsignal.Logger.Backend do
@behaviour :gen_event

def init({__MODULE__, group}) do
{:ok, group}
def init({__MODULE__, options}) do
{:ok, Keyword.merge([group: "app"], options)}
end

def init(_) do
{:ok, "app"}
def handle_event({level, _gl, {Logger, message, _timestamp, metadata}}, options) do
Appsignal.Logger.log(level, options[:group], IO.chardata_to_string(message), Enum.into(metadata, %{}))
{:ok, options}
end

def handle_event({level, _gl, {Logger, message, _timestamp, metadata}}, group) do
Appsignal.Logger.log(level, group, IO.chardata_to_string(message), Enum.into(metadata, %{}))
{:ok, group}
end

def handle_call(_messsage, group) do
{:ok, nil, group}
def handle_call(_messsage, options) do
{:ok, nil, options}
end
end
2 changes: 1 addition & 1 deletion test/appsignal/logger/backend_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule Appsignal.Logger.BackendTest do
]
}
},
"phoenix"
[group: "phoenix"]
)

assert [{"phoenix", 3, "foo bar baz", _}] = Appsignal.Test.Nif.get!(:log)
Expand Down

0 comments on commit c48cc0b

Please sign in to comment.