From f43fa83bcc84fd1d77eb57827ced8bd14be580b6 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Mon, 31 Oct 2011 23:40:38 -0400 Subject: [PATCH] Fix a bug with how the remaining free space is calculated --- src/lager_format.erl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lager_format.erl b/src/lager_format.erl index b3fa86e..543ac07 100644 --- a/src/lager_format.erl +++ b/src/lager_format.erl @@ -145,7 +145,7 @@ build([], Acc, MaxLen, _O) -> build2([{C,As,F,Ad,P,Pad,Enc}|Cs], Count, MaxLen) -> {S, Len} = control2(C, As, F, Ad, P, Pad, Enc, MaxLen div Count), - [S|build2(Cs, Count - 1, MaxLen - abs(Len))]; + [S|build2(Cs, Count - 1, MaxLen - Len)]; build2([C|Cs], Count, MaxLen) -> [C|build2(Cs, Count, MaxLen)]; build2([], _, _) -> []. @@ -221,27 +221,27 @@ control(C, A, F, Adj, P, Pad, Enc, L) -> control2($w, [A], F, Adj, P, Pad, _Enc, L) -> Term = lager_trunc_io:fprint(A, L, [{lists_as_strings, false}]), Res = term(Term, F, Adj, P, Pad), - {Res, L - lists:flatlength(Res)}; + {Res, lists:flatlength(Res)}; control2($p, [A], F, Adj, P, Pad, _Enc, L) -> Term = lager_trunc_io:fprint(A, L, [{lists_as_strings, true}]), Res = term(Term, F, Adj, P, Pad), - {Res, L - lists:flatlength(Res)}; + {Res, lists:flatlength(Res)}; control2($W, [A,Depth], F, Adj, P, Pad, _Enc, L) when is_integer(Depth) -> Term = lager_trunc_io:fprint(A, L, [{depth, Depth}, {lists_as_strings, false}]), Res = term(Term, F, Adj, P, Pad), - {Res, L - lists:flatlength(Res)}; + {Res, lists:flatlength(Res)}; control2($P, [A,Depth], F, Adj, P, Pad, _Enc, L) when is_integer(Depth) -> Term = lager_trunc_io:fprint(A, L, [{depth, Depth}, {lists_as_strings, true}]), Res = term(Term, F, Adj, P, Pad), - {Res, L - lists:flatlength(Res)}; + {Res, lists:flatlength(Res)}; control2($s, [L0], F, Adj, P, Pad, latin1, L) -> List = lager_trunc_io:fprint(maybe_flatten(L0), L, [{force_strings, true}]), Res = string(List, F, Adj, P, Pad), - {Res, L - lists:flatlength(Res)}; + {Res, lists:flatlength(Res)}; control2($s, [L0], F, Adj, P, Pad, unicode, L) -> List = lager_trunc_io:fprint(unicode:characters_to_list(L0), L, [{force_strings, true}]), Res = uniconv(string(List, F, Adj, P, Pad)), - {Res, L - lists:flatlength(Res)}. + {Res, lists:flatlength(Res)}. maybe_flatten(X) when is_list(X) -> lists:flatten(X);