Skip to content

Commit

Permalink
Formatter config can be a map (#123)
Browse files Browse the repository at this point in the history
* Formatter config can be a map

* Update docs to use maps as formatter config
  • Loading branch information
dvic authored Jul 26, 2024
1 parent a43bcd3 commit 222e612
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ config :logger, :default_handler,
or during runtime:

```elixir
:logger.update_handler_config(:default, :formatter, {Basic, metadata: {:all_except, [:conn]}})
:logger.update_handler_config(:default, :formatter, {Basic, %{metadata: {:all_except, [:conn]}}})
```

## Docs
Expand Down
4 changes: 2 additions & 2 deletions lib/logger_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ defmodule LoggerJSON do
or during runtime (eg. in your `application.ex`):
:logger.update_handler_config(:default, :formatter, {Basic, []})
:logger.update_handler_config(:default, :formatter, {Basic, %{}})
## Configuration
Expand All @@ -50,7 +50,7 @@ defmodule LoggerJSON do
or during runtime:
:logger.update_handler_config(:default, :formatter, {Basic, metadata: {:all_except, [:conn]}})
:logger.update_handler_config(:default, :formatter, {Basic, %{metadata: {:all_except, [:conn]}}})
### Shared Options
Expand Down
1 change: 1 addition & 0 deletions lib/logger_json/formatters/basic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ defmodule LoggerJSON.Formatters.Basic do

@impl true
def format(%{level: level, meta: meta, msg: msg}, opts) do
opts = Keyword.new(opts)
metadata_keys_or_selector = Keyword.get(opts, :metadata, [])
metadata_selector = update_metadata_selector(metadata_keys_or_selector, @processed_metadata_keys)
redactors = Keyword.get(opts, :redactors, [])
Expand Down
1 change: 1 addition & 0 deletions lib/logger_json/formatters/datadog.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ defmodule LoggerJSON.Formatters.Datadog do

@impl true
def format(%{level: level, meta: meta, msg: msg}, opts) do
opts = Keyword.new(opts)
redactors = Keyword.get(opts, :redactors, [])
hostname = Keyword.get(opts, :hostname, :system)

Expand Down
1 change: 1 addition & 0 deletions lib/logger_json/formatters/elastic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ defmodule LoggerJSON.Formatters.Elastic do

@impl LoggerJSON.Formatter
def format(%{level: level, meta: meta, msg: msg}, opts) do
opts = Keyword.new(opts)
metadata_keys_or_selector = Keyword.get(opts, :metadata, [])
metadata_selector = update_metadata_selector(metadata_keys_or_selector, @processed_metadata_keys)
redactors = Keyword.get(opts, :redactors, [])
Expand Down
1 change: 1 addition & 0 deletions lib/logger_json/formatters/google_cloud.ex
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ defmodule LoggerJSON.Formatters.GoogleCloud do

@impl true
def format(%{level: level, meta: meta, msg: msg}, opts) do
opts = Keyword.new(opts)
redactors = Keyword.get(opts, :redactors, [])
service_context = Keyword.get_lazy(opts, :service_context, fn -> %{service: to_string(node())} end)
project_id = Keyword.get(opts, :project_id)
Expand Down

0 comments on commit 222e612

Please sign in to comment.