Skip to content

Commit

Permalink
fix: check if Decimal is compiled in encoder (#135)
Browse files Browse the repository at this point in the history
If Decimal is not included in the main app depending on LoggerJSON,
the following line in `LoggerJSON.Formatter.RedactorEncoder` is not included:

```elixir
    def encode(%Decimal{} = decimal, _redactors), do: decimal
```
  • Loading branch information
davidjulien authored Sep 16, 2024
1 parent 1371032 commit 99f2fa7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/logger_json/formatter/redactor_encoder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ defmodule LoggerJSON.Formatter.RedactorEncoder do
def encode(%DateTime{} = datetime, _redactors), do: datetime
def encode(%Date{} = date, _redactors), do: date
def encode(%Time{} = time, _redactors), do: time
def encode(%Decimal{} = decimal, _redactors), do: decimal

if Code.ensure_loaded?(Decimal) do
def encode(%Decimal{} = decimal, _redactors), do: decimal
end

def encode(%_struct{} = struct, redactors) do
struct
Expand Down
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ defmodule LoggerJSON.Mixfile do
[
{:jason, "~> 1.4"},
{:plug, "~> 1.15", optional: true},
{:decimal, ">= 0.0.0", optional: true},
{:ecto, "~> 3.11", optional: true},
{:telemetry, "~> 1.0", optional: true},
{:stream_data, "~> 1.0", only: [:dev, :test]},
Expand Down

0 comments on commit 99f2fa7

Please sign in to comment.