Skip to content

Commit 99f2fa7

Browse files
authored
fix: check if Decimal is compiled in encoder (#135)
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 ```
1 parent 1371032 commit 99f2fa7

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/logger_json/formatter/redactor_encoder.ex

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ defmodule LoggerJSON.Formatter.RedactorEncoder do
3636
def encode(%DateTime{} = datetime, _redactors), do: datetime
3737
def encode(%Date{} = date, _redactors), do: date
3838
def encode(%Time{} = time, _redactors), do: time
39-
def encode(%Decimal{} = decimal, _redactors), do: decimal
39+
40+
if Code.ensure_loaded?(Decimal) do
41+
def encode(%Decimal{} = decimal, _redactors), do: decimal
42+
end
4043

4144
def encode(%_struct{} = struct, redactors) do
4245
struct

mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ defmodule LoggerJSON.Mixfile do
3737
[
3838
{:jason, "~> 1.4"},
3939
{:plug, "~> 1.15", optional: true},
40+
{:decimal, ">= 0.0.0", optional: true},
4041
{:ecto, "~> 3.11", optional: true},
4142
{:telemetry, "~> 1.0", optional: true},
4243
{:stream_data, "~> 1.0", only: [:dev, :test]},

0 commit comments

Comments
 (0)