Skip to content

Commit

Permalink
Format report data for json
Browse files Browse the repository at this point in the history
  • Loading branch information
reachfh committed Jun 29, 2024
1 parent bc0e720 commit d5d8a94
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/logger_formatter_json.erl
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,27 @@ is_printable(X) when is_binary(X) ->
% end;
io_lib:printable_unicode_list(unicode:characters_to_list(X, unicode)).

% Format strings for print
print_string(X, Config) when is_binary(X) ->
case is_printable(X) of
true -> X;
_ -> io_lib:format(p(Config), [X])
end;

print_string(X, Config) when is_list(X) ->
case printable_list(lists:flatten(X)) of
true -> list_to_binary(X);
_ -> io_lib:format(p(Config), [X])
end.

-spec format_msg(Msg, Meta, Config) ->
binary()
| 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({report, Report}, _Meta, _Config) when is_map(Report) -> Report;
format_msg({report, Report}, _Meta, Config) when is_map(Report) ->
maps:map(fun(_K, V) -> print_string(to_string(V, Config), Config) end, Report);

format_msg({report, _} = Msg, Meta, #{report_cb := Fun} = Config)
when is_function(Fun, 1); is_function(Fun, 2) ->
Expand Down

0 comments on commit d5d8a94

Please sign in to comment.