Skip to content

Commit

Permalink
Correct printing of strings in mixed error reports (reported by Bryan…
Browse files Browse the repository at this point in the history
… Hughes)

Since the lager_format rewrite, ~p and ~w now have different behaviour
with regard to printing lists as strings.
  • Loading branch information
Vagabond committed Nov 6, 2011
1 parent ce9a47b commit 16fb558
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/error_logger_lager_h.erl
Expand Up @@ -266,9 +266,9 @@ print_silly_list([], Fmt, Acc) ->
lager_trunc_io:format(string:join(lists:reverse(Fmt), ", "),
lists:reverse(Acc), 4096);
print_silly_list([{K,V}|T], Fmt, Acc) ->
print_silly_list(T, ["~w: ~w" | Fmt], [V, K | Acc]);
print_silly_list(T, ["~p: ~p" | Fmt], [V, K | Acc]);
print_silly_list([H|T], Fmt, Acc) ->
print_silly_list(T, ["~w" | Fmt], [H | Acc]).
print_silly_list(T, ["~p" | Fmt], [H | Acc]).

print_val(Val) ->
{Str, _} = lager_trunc_io:print(Val, 500),
Expand Down
10 changes: 9 additions & 1 deletion test/lager_test_backend.erl
Expand Up @@ -509,7 +509,15 @@ error_logger_redirect_test_() ->
?assert(length(lists:flatten(Msg)) < 5100)
end
},

{"strings in a mixed report are printed as strings",
fun() ->
sync_error_logger:info_report(["this is less silly", {than, "this"}]),
_ = gen_event:which_handlers(error_logger),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[info] ~w \"this is less silly\", than: \"this\"", [self()])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"info messages are printed",
fun() ->
sync_error_logger:info_msg("doom, doom has come upon you all"),
Expand Down

0 comments on commit 16fb558

Please sign in to comment.