Skip to content

Commit

Permalink
Merge pull request #3124 from esl/mu-pretty-stacktrace-formatting
Browse files Browse the repository at this point in the history
Format stacktrace args properly

This PR addresses ugly stacktraces.
Before:

"stacktrace":"ets:lookup/[prepared_statements,auth_list_users]:0 mongoose_rdbms:query_name_to_string/1:225 mongoose_rdbms:execute_successfully/3:217 ejabberd_auth_rdbms:get_vh_registered_users/2:206 lists:flatmap/2:1250 lists:flatmap/2:1250 rpc:'-handle_call_call/6-fun-0-'/5:197"
After:

"stacktrace_args":"[prepared_statements,auth_list_users]",
"stacktrace":"ets:lookup/2:0 mongoose_rdbms:query_name_to_string/1:225 mongoose_rdbms:execute_successfully/3:217 ejabberd_auth_rdbms:get_vh_registered_users/2:206 lists:flatmap/2:1250 lists:flatmap/2:1250 rpc:'-handle_call_call/6-fun-0-'/5:197"
  • Loading branch information
NelsonVides authored May 19, 2021
2 parents ca4fb80 + e58ce81 commit 0dc6e59
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/logger/mongoose_log_filter.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ format_packet_filter(Event, _) ->
Event.

format_stacktrace_filter(Event=#{msg := {report, Msg=#{stacktrace := S}}}, _) ->
Event#{msg => {report, Msg#{stacktrace => format_stacktrace(S)} }};
FmtArgs = format_stacktrace_args(S),
Msg2 = case FmtArgs of
<<>> -> Msg;
_ -> Msg#{stacktrace_args => FmtArgs}
end,
Msg3 = case format_stacktrace(S) of
<<>> -> Msg2;
FmtStack -> Msg2#{stacktrace => FmtStack}
end,
Event#{msg => {report, Msg3 }};
format_stacktrace_filter(Event, _) ->
Event.

Expand Down Expand Up @@ -117,10 +126,17 @@ format_microseconds(N) ->
{offset, 0},
{time_designator, $T}]).

format_stacktrace_args([{_Mod,_Fun,Args,_Info}|_]) when is_list(Args) ->
iolist_to_binary(io_lib:format("~p", [Args]));
format_stacktrace_args(_) ->
<<>>.

format_stacktrace(Stacktrace) ->
iolist_to_binary(do_format_stacktrace(Stacktrace)).

do_format_stacktrace([{Mod,Fun,Args,Info}|T]) when is_list(Args) ->
Arity = length(Args),
do_format_stacktrace([{Mod,Fun,Arity,Info}|T]);
do_format_stacktrace([{Mod,Fun,Arity,Info}|T]) ->
Line = proplists:get_value(line, Info, 0),
H = io_lib:format("~p:~p/~p:~p", [Mod, Fun, Arity, Line]),
Expand Down

0 comments on commit 0dc6e59

Please sign in to comment.