Skip to content

Commit dfe3f89

Browse files
committed
Fix filtering documentation
The filtering documentation implied that the msg attribute of the logger event map could be a binary, but according to the erlang types (https://www.erlang.org/doc/apps/kernel/logger.html#t:log_event/0) it can't be a binary. This change updates the docs with an example that comports with the actual typing.
1 parent 67042e8 commit dfe3f89

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/logger/lib/logger.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,8 +436,8 @@ defmodule Logger do
436436
defmodule LogFilter do
437437
def filter(log_event, _opts) do
438438
case log_event do
439-
%{msg: msg} when is_binary(msg) ->
440-
if msg =~ "password" do
439+
%{msg: {:string, msg}} ->
440+
if ensure_binary(msg) =~ "password" do
441441
:stop
442442
else
443443
:ignore
@@ -447,6 +447,14 @@ defmodule Logger do
447447
:ignore
448448
end
449449
end
450+
451+
defp ensure_binary(charlist) when is_list(charlist) do
452+
List.to_string(charlist)
453+
end
454+
455+
defp ensure_binary(string) when is_binary(string) do
456+
string
457+
end
450458
end
451459
452460
The filter may return the possibly modified event (to change the

0 commit comments

Comments
 (0)