Skip to content

Commit

Permalink
Deal with iodata
Browse files Browse the repository at this point in the history
  • Loading branch information
reachfh committed Jul 20, 2024
1 parent c5be398 commit dc1b893
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/logger_formatter_json.erl
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,19 @@ print_string(X, Config) when is_list(X) ->
| map() when Msg :: {io:format(), [term()]}
| {report, logger:report()}
| {string, unicode:chardata()} , Meta :: logger:metadata() , Config :: config().
format_msg({string, Chardata}, Meta, Config) -> format_msg({"~ts", [Chardata]}, Meta, Config);
% format_msg({string, Chardata}, Meta, Config) -> format_msg({"~ts", [Chardata]}, Meta, Config);
format_msg({string, Chardata}, Meta, Config) when is_binary(Chardata) ->
format_msg({string, unicode:characters_to_list(Chardata, unicode)}, Meta, Config);

format_msg({string, Chardata}, Meta, Config) ->
case io_lib:printable_unicode_list(Chardata) of
true -> format_msg({"~ts", [Chardata]}, Meta, Config);
false ->
format_msg({"~ts", [iolist_to_binary(Chardata)]}, Meta, Config)
% Flat = lists:flatten(Chardata),
% Strings = lists:map(fun (X) -> to_string(X, Config) end, Flat),
% format_msg({"~ts", [lists:flatten(Strings)]}, Meta, Config)
end;

format_msg({report, Report}, _Meta, Config) when is_map(Report) ->
maps:map(fun (_K, V) -> print_string(to_string(V, Config), Config) end, Report);
Expand Down

0 comments on commit dc1b893

Please sign in to comment.