Binary in ?LOG_ERROR(<<"Connection error. Error: ~p, Reason: ~tp.">>, [Error, Reason])

Hello, I have primary filter:

logger:add_primary_filter(amqp_sup_noise_filter, {fun amqp_sup_noise_filter/2, no_args}),

where

amqp_sup_noise_filter(#{
    msg := {report, #{report := [{supervisor, {_, amqp_connection_sup}} | _]}}
}, _Args) ->
    stop;

amqp_sup_noise_filter(#{
    msg := {report, #{report := [{supervisor, {_, amqp_connection_type_sup}} | _]}}
}, _Args) ->
    stop;

amqp_sup_noise_filter(#{
    msg := {report, #{report := [{supervisor, {_, amqp_channel_sup}} | _]}}
}, _Args) ->
    stop;

amqp_sup_noise_filter(LogEvent, _Args) ->
    LogEvent.

There are call ?LOG_ERROR

?LOG_ERROR(<<"Connection error. Error: ~p, Reason: ~tp.">>, [Error, Reason]),

And I see in log file

error Connection error. Error: error, Reason: {badmatch,<<"admin">>}.
debug logger: removed_failing_filter, filter: {amqp_sup_noise_filter,{#Fun<my_app_app.0.14579140>,no_args}}, owner: primary, log_event: #{level => error,meta => #{file => "/home/user/my_app/apps/my_app_rabbitmq/src/my_app_rabbitmq_listener.erl",gl => <0.908.0>,line => 179,mfa => {my_app_rabbitmq_listener,handle_info,2},pid => <0.915.0>,time => 1646596223107147},msg => {<<"Connection error. Error: ~p, Reason: ~tp.">>,[error,{badmatch,<<"admin">>}]}}, reason: {bad_return_value,#{level => error,meta => #{file => "/home/user/my_app/apps/my_app_rabbitmq/src/my_app_rabbitmq_listener.erl",gl => <0.908.0>,line => 179,mfa => {my_app_rabbitmq_listener,handle_info,2},pid => <0.915.0>,time => 1646596223107147},msg => {<<"Connection error. Error: ~p, Reason: ~tp.">>,[error,{badmatch,<<"admin">>}]}}}

After that, the filter stops working.
Is it error or maybe I use it wrong?

I use Erlang/OTP 23.2.3.

2 Likes

Encountered the same problem recently. Seems like it’s a bug in Logger. There’s opened PR in Erlang/OTP repository.

2 Likes

Thanks a lot!

1 Like