From 16fb55890c97d0a0eb5a95646903f39ed1e9ceb2 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Sun, 6 Nov 2011 14:40:17 -0500 Subject: [PATCH] Correct printing of strings in mixed error reports (reported by Bryan Hughes) Since the lager_format rewrite, ~p and ~w now have different behaviour with regard to printing lists as strings. --- src/error_logger_lager_h.erl | 4 ++-- test/lager_test_backend.erl | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index a6501b6..dc24591 100644 --- a/src/error_logger_lager_h.erl +++ b/src/error_logger_lager_h.erl @@ -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), diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index 9a5aff1..e43d1e6 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -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"),