Skip to content

Commit

Permalink
feat: rename JsonFormatter to avoid confusion with Logger.Formatter
Browse files Browse the repository at this point in the history
`CozyLogger.JSON` provides the `format/4` function only, so it is not
a full-featured `Logger.Formatter`.
  • Loading branch information
c4710n committed Oct 23, 2023
1 parent ec37a5f commit 0f6f360
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 16 deletions.
14 changes: 8 additions & 6 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ if is_old_elixir? do

# use log formatter provided by CozyLogger
config :logger, :console,
format: {CozyLogger.JsonFormatter, :format},
format: {CozyLogger.JSON, :format},
truncate: :infinity,
utc_log: true,
metadata: :all,
colors: [enabled: false],
utc_log: true
colors: [enabled: false]
else
config :logger, :default_formatter,
format: {CozyLogger.JsonFormatter, :format},
format: {CozyLogger.JSON, :format},
truncate: :infinity,
utc_log: true,
metadata: :all,
colors: [enabled: false],
utc_log: true
colors: [enabled: false]
end
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
defmodule CozyLogger.JsonFormatter do
defmodule CozyLogger.JSON do
@moduledoc """
A JSON formatter for Elixir built-in console backend.
Formatting log messages as JSON.
## Usage
Elixir v1.15 or later:
# customize format message with this formatter.
config :logger, :default_formatter,
format: {CozyLogger.JsonFormatter, :format},
metadata: :all,
colors: [enabled: false],
format: {#{inspect(__MODULE__)}, :format},
truncate: :infinity,
utc_log: true
utc_log: true,
metadata: :all,
colors: [enabled: false]
Prior to Elixir v1.15:
Expand All @@ -24,7 +24,7 @@ defmodule CozyLogger.JsonFormatter do
# customize format message with this formatter.
config :logger, :console,
format: {CozyLogger.JsonFormatter, :format},
format: {#{inspect(__MODULE__)}, :format},
metadata: :all,
colors: [enabled: false]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
defmodule CozyLogger.JsonFormatterTest do
defmodule CozyLogger.JSONTest do
use ExUnit.Case, async: true

alias CozyLogger.JsonFormatter
alias CozyLogger.JSON

defmodule TestStruct do
defstruct [:field]
end

defp encode_as_string!(value) do
value
|> JsonFormatter.encode!()
|> JSON.encode!()
|> to_string()
end

Expand Down

0 comments on commit 0f6f360

Please sign in to comment.