Logflare / logflare_logger_backend

Logger backend to send Elixir logs to Logflare.
MIT License
88 stars 17 forks source link

batch_cache sort_by_created_asc/1 anonymous fn/3 #79

Open fantypants opened 2 years ago

fantypants commented 2 years ago

batch_cache:44 returns

:gen_event handler LogflareLogger.HttpBackend installed in Logger terminating
** (exit) an exception was raised:
    ** (BadFunctionError) expected a function, got: :asc
        (elixir) lib/enum.ex:2354: anonymous fn/3 in Enum.sort_by/3
        (stdlib) lists.erl:969: :lists.sort/2
        (elixir) lib/enum.ex:2354: Enum.sort_by/3
        (logflare_logger_backend) lib/logflare_logger/batch_cache.ex:44: LogflareLogger.BatchCache.flush/1
        (logflare_logger_backend) lib/logflare_logger/http_backend.ex:147: LogflareLogger.HttpBackend.flush!/1
        (stdlib) gen_event.erl:577: :gen_event.server_update/4
        (stdlib) gen_event.erl:559: :gen_event.server_notify/4
        (stdlib) gen_event.erl:347: :gen_event.handle_msg/6
        (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3

Relevant fix: Change: Enum.sort_by(pending_events, & &1.id, :asc) to Enum.sort_by(pending_events, &(&1.id), &<=/2)

chasers commented 2 years ago

Just curious what version of Elixir are you on?

fantypants commented 2 years ago

Erlang/OTP 22 [erts-10.6.4] [source] [64-bit] [smp:16:16] [ds:16:16:10] [async-threads:1]

Elixir 1.9.1 (compiled with Erlang/OTP 22)

Thanks for the prompt reply!

chasers commented 2 years ago

Ah yeah, this is why. :asc was introduced later. But no reason we can't update this for backward compatibility.

fantypants commented 2 years ago

Ah yeah, this is why. :asc was introduced later. But no reason we can't update this for backward compatibility.

have a suss at the PR I just submitted, let me know if there's anything we can do further to support