Logger filter doesn't document successful return state properly
Closed this issue · 1 comments
Elixir and Erlang/OTP versions
Erlang/OTP 28 [erts-16.0.1] [source] [64-bit] [smp:20:20] [ds:20:20:10] [async-threads:1] [jit:ns]
Elixir 1.18.4 (compiled with Erlang/OTP 27)
Operating system
Linux
Current behavior
The logger filter docs indicates :log to be the return value for the filter passing. But when using the :log return value, the filter was removed (:removed_failing_filter) with the reason {:bad_return_value, :log}]. For example:
defmodule LogFilter do
def filter(log_event, _opts) do
case log_event do
%{msg: {:string, msg}} when is_binary(msg) ->
if msg =~ "password" do
:log
else
:stop
end
_ ->
:stop
end
end
endconfig :repro, :logger, [
{
:handler,
:repo_logger,
:logger_std_h,
%{
config: %{
file: ~c"repro.log"
},
formatter: Logger.Formatter.new(),
filters: [
repro_filter: {&LogFilter.filter/2, []}
],
filter_default: :stop
}
}
]Expected behavior
The erlang :logger docs indicates that the log event (log_event for the example in the Elixir docs) should be returned instead of :log. Replacing :log with %{log_event | msg: {:string, "[Filtered]"}} doesn't cause an error and continues to log properly. Also, based on erlang's logging guide, shouldn't :ignore be used when the filter passes unless the log event is being changed by the filter which isn't really what Elixir's docs say?
You are correct on all accounts. Would you like to send a PR updating the docs?