Преглед на файлове

Merge pull request #12 from basho/adt-fix-print-bugs

Adt fix print bugs
pull/13/head
Andrew Thompson преди 13 години
родител
ревизия
4cfa3ee400
променени са 2 файла, в които са добавени 23 реда и са изтрити 7 реда
  1. +23
    -6
      src/lager_trunc_io.erl
  2. +0
    -1
      test/lager_test_backend.erl

+ 23
- 6
src/lager_trunc_io.erl Целия файл

@ -101,8 +101,14 @@ format([[$~|H]| T], [AH | AT], Max, Acc, ArgAcc) when length(H) == 1 ->
{String, Length} ->
{Value, RealLen} = case H of
"s" ->
% strip off the doublequotes
{string:substr(String, 2, length(String) -2), Length -2};
% strip off the doublequotes, if applicable
Trimmed = case {hd(String), lists:last(String)} == {$", $"} of
true ->
string:strip(String, both, $");
_ ->
String
end,
{Trimmed, length(Trimmed)};
_ ->
{String, Length}
end,
@ -303,10 +309,10 @@ list_bodyc(X,Max) -> %% improper list
%%
alist_start([], _) -> {"[]", 2};
alist_start(_, Max) when Max < 4 -> {"...", 3};
alist_start([H|T], Max) when H >= 16#20, H =< 16#7e -> % definitely printable
alist_start([H|T], Max) when is_integer(H), H >= 16#20, H =< 16#7e -> % definitely printable
{L, Len} = alist([H|T], Max-1),
{[$"|L], Len + 1};
alist_start([H|T], Max) when H == 9; H == 10; H == 13 -> % show as space
alist_start([H|T], Max) when H =:= 9; H =:= 10; H =:= 13 -> % show as space
{L, Len} = alist(T, Max-1),
{[$ |L], Len + 1};
alist_start(L, Max) ->
@ -315,10 +321,10 @@ alist_start(L, Max) ->
alist([], _) -> {"\"", 1};
alist(_, Max) when Max < 5 -> {"...\"", 4};
alist([H|T], Max) when H >= 16#20, H =< 16#7e -> % definitely printable
alist([H|T], Max) when is_integer(H), H >= 16#20, H =< 16#7e -> % definitely printable
{L, Len} = alist(T, Max-1),
{[H|L], Len + 1};
alist([H|T], Max) when H == 9; H == 10; H == 13 -> % show as space
alist([H|T], Max) when H =:= 9; H =:= 10; H =:= 13 -> % show as space
{L, Len} = alist(T, Max-1),
{[$ |L], Len + 1};
alist(L, Max) ->
@ -428,4 +434,15 @@ sane_float_printing_test() ->
?assertEqual("0.1234567", lists:flatten(format("~p", [0.1234567], 50))),
ok.
float_inside_list_test() ->
?assertEqual("\"a\"[38.233913133184835,99]", lists:flatten(format("~p", [[$a, 38.233913133184835, $c]], 50))),
?assertEqual("\"a\"[38.233913133184835,99]", lists:flatten(format("~s", [[$a, 38.233913133184835, $c]], 50))),
ok.
quote_strip_test() ->
?assertEqual("\"hello\"", lists:flatten(format("~p", ["hello"], 50))),
?assertEqual("hello", lists:flatten(format("~s", ["hello"], 50))),
?assertEqual("hello", lists:flatten(format("~s", [hello], 50))),
?assertEqual("hello", lists:flatten(format("~p", [hello], 50))),
ok.
-endif.

+ 0
- 1
test/lager_test_backend.erl Целия файл

@ -647,7 +647,6 @@ error_logger_redirect_test_() ->
safe_format_test() ->
?assertEqual("foo bar", lists:flatten(lager:safe_format("~p ~p", [foo, bar], 1024))),
?assertEqual("FORMAT ERROR: \"~p ~p ~p\" [foo,bar]", lists:flatten(lager:safe_format("~p ~p ~p", [foo, bar], 1024))),
?assertEqual("FORMAT ERROR: \"~s\" [1]", lists:flatten(lager:safe_format("~s", [1], 1024))),
ok.
-endif.

Зареждане…
Отказ
Запис