Kaynağa Gözat

Whitespace cleanups

pull/74/head
Andrew Thompson 13 yıl önce
ebeveyn
işleme
05718792ae
9 değiştirilmiş dosya ile 162 ekleme ve 164 silme
  1. +12
    -12
      include/lager.hrl
  2. +1
    -1
      src/lager_app.erl
  3. +10
    -10
      src/lager_backend_utils.erl
  4. +1
    -1
      src/lager_default_formatter.erl
  5. +9
    -9
      src/lager_file_backend.erl
  6. +52
    -53
      src/lager_format.erl
  7. +0
    -1
      src/lager_transform.erl
  8. +22
    -22
      src/lager_trunc_io.erl
  9. +55
    -55
      test/crash.erl

+ 12
- 12
include/lager.hrl Dosyayı Görüntüle

@ -15,12 +15,12 @@
%% under the License.
-record(lager_log_message,{
destinations,
metadata,
severity_as_int,
timestamp,
message
}).
destinations,
metadata,
severity_as_int,
timestamp,
message
}).
-define(LEVELS,
@ -65,12 +65,12 @@
-define(NOTIFY(Level, Pid, Format, Args),
gen_event:notify(lager_event,#lager_log_message{destinations=[],
message=io_lib:format(Format,Args),
metadata=[{pid,Pid},{line,?LINE},{file,?FILE},{module,?MODULE}],
timestamp=lager_util:format_time(),
severity_as_int=lager_util:level_to_num(Level)
})).
message=io_lib:format(Format,Args),
metadata=[{pid,Pid},{line,?LINE},{file,?FILE},{module,?MODULE}],
timestamp=lager_util:format_time(),
severity_as_int=lager_util:level_to_num(Level)
})).
%% FOR INTERNAL USE ONLY
%% internal non-blocking logging call
%% there's some special handing for when we try to log (usually errors) while

+ 1
- 1
src/lager_app.erl Dosyayı Görüntüle

@ -96,7 +96,7 @@ to_config({Name,Severity,Size,Rotation,Count,Format}) ->
-ifdef(TEST).
application_config_mangling_test_() ->
[{"Explode the file backend handlers",
?_assertMatch(
?_assertMatch(
[{lager_console_backend, info},
{{lager_file_backend,"error.log"},{"error.log",error,10485760, "$D0",5}},
{{lager_file_backend,"console.log"},{"console.log",info,10485760, "$D0",5}}

+ 10
- 10
src/lager_backend_utils.erl Dosyayı Görüntüle

@ -22,20 +22,20 @@
-spec is_loggable(#lager_log_message{},integer(),term()) -> boolean().
is_loggable(#lager_log_message{severity_as_int=Severity,destinations=Destinations},SeverityThreshold,MyName)->
%% ?debugFmt("is_loggable: Severity=~p, Threshold=~p, Destinations=~p, MyName=~p", [Severity,SeverityThreshold,Destinations,MyName]),
Severity =< SeverityThreshold orelse lists:member(MyName, Destinations).
is_loggable(#lager_log_message{severity_as_int=Severity,destinations=Destinations},SeverityThreshold,MyName) ->
%?debugFmt("is_loggable: Severity=~p, Threshold=~p, Destinations=~p, MyName=~p", [Severity,SeverityThreshold,Destinations,MyName]),
Severity =< SeverityThreshold orelse lists:member(MyName, Destinations).
-ifdef(TEST).
is_loggable_test_() ->
[
{"Loggable by severity only", ?_assert(is_loggable(#lager_log_message{severity_as_int=1,destinations=[]},2,me))},
{"Not loggable by severity only", ?_assertNot(is_loggable(#lager_log_message{severity_as_int=2,destinations=[]},1,me))},
{"Loggable by severity with destination", ?_assert(is_loggable(#lager_log_message{severity_as_int=1,destinations=[you]},2,me))},
{"Not loggable by severity with destination", ?_assertNot(is_loggable(#lager_log_message{severity_as_int=2,destinations=[you]},1,me))},
{"Loggable by destination overriding severity", ?_assert(is_loggable(#lager_log_message{severity_as_int=2,destinations=[me]},1,me))}
].
[
{"Loggable by severity only", ?_assert(is_loggable(#lager_log_message{severity_as_int=1,destinations=[]},2,me))},
{"Not loggable by severity only", ?_assertNot(is_loggable(#lager_log_message{severity_as_int=2,destinations=[]},1,me))},
{"Loggable by severity with destination", ?_assert(is_loggable(#lager_log_message{severity_as_int=1,destinations=[you]},2,me))},
{"Not loggable by severity with destination", ?_assertNot(is_loggable(#lager_log_message{severity_as_int=2,destinations=[you]},1,me))},
{"Loggable by destination overriding severity", ?_assert(is_loggable(#lager_log_message{severity_as_int=2,destinations=[me]},1,me))}
].
-endif.

+ 1
- 1
src/lager_default_formatter.erl Dosyayı Görüntüle

@ -133,7 +133,7 @@ basic_test_() ->
metadata=[{pid,"Fallback"}]},
[date, " ", time," [",severity,"] ",{does_not_exist,pid}, " ", message, "\n"]
)))
}
}
].
-endif.

+ 9
- 9
src/lager_file_backend.erl Dosyayı Görüntüle

@ -50,16 +50,16 @@
size = 0 :: integer(),
date,
count = 10,
formatter,
formatter_config
formatter,
formatter_config
}).
%% @private
-spec init([{string(), lager:log_level()},...]) -> {ok, #state{}}.
init([LogFile,{Formatter}]) ->
init([LogFile,{Formatter,[]}]);
init([LogFile,{Formatter,[]}]);
init([LogFile,{Formatter,FormatterConfig}]) ->
case validate_logfile(LogFile) of
case validate_logfile(LogFile) of
{Name, Level, Size, Date, Count} ->
schedule_rotation(Name, Date),
State = case lager_util:open_logfile(Name, true) of
@ -72,13 +72,13 @@ init([LogFile,{Formatter,FormatterConfig}]) ->
#state{name=Name, level=lager_util:level_to_num(Level),
flap=true, size=Size, date=Date, count=Count, formatter=Formatter, formatter_config=FormatterConfig}
end,
{ok, State};
false ->
ignore
end;
init(LogFile) ->
init([LogFile,{lager_default_formatter,[]}]).
init([LogFile,{lager_default_formatter,[]}]).
%% @private
@ -95,7 +95,7 @@ handle_event(Message,
#state{name=Name, level=L,formatter=Formatter,formatter_config=FormatConfig} = State) ->
case lager_backend_utils:is_loggable(Message,L,{lager_file_backend, Name}) of
true ->
{ok,write(State, Message#lager_log_message.severity_as_int, Formatter:format(Message,FormatConfig)) };
{ok,write(State, Message#lager_log_message.severity_as_int, Formatter:format(Message,FormatConfig)) };
false ->
{ok, State}
end;
@ -357,7 +357,7 @@ filesystem_test_() ->
?MODULE}], ?DEBUG,
{lager_file_backend, "test.log"}}]}),
lager:error("Test message"),
timer:sleep(1000),
timer:sleep(1000),
{ok, Bin} = file:read_file("test.log"),
?assertMatch([_, _, "[error]", _, "Test message\n"], re:split(Bin, " ", [{return, list}, {parts, 5}]))
end
@ -421,7 +421,7 @@ formatting_test_() ->
?assertMatch({ok, <<"2> [error] Test message\n">>},file:read_file("test2.log"))
end
}
]}.
]}.
-endif.

+ 52
- 53
src/lager_format.erl Dosyayı Görüntüle

@ -88,7 +88,7 @@ field_value(Fmt, Args) ->
field_value([C|Fmt], Args, F) when is_integer(C), C >= $0, C =< $9 ->
field_value(Fmt, Args, 10*F + (C - $0));
field_value(Fmt, Args, F) -> %Default case
field_value(Fmt, Args, F) -> %Default case
{F,Fmt,Args}.
pad_char([$.,$*|Fmt], [Pad|Args]) -> {Pad,Fmt,Args};
@ -96,7 +96,7 @@ pad_char([$.,Pad|Fmt], Args) -> {Pad,Fmt,Args};
pad_char(Fmt, Args) -> {$\s,Fmt,Args}.
%% collect_cc([FormatChar], [Argument]) ->
%% {Control,[ControlArg],[FormatChar],[Arg]}.
%% {Control,[ControlArg],[FormatChar],[Arg]}.
%% Here we collect the argments for each control character.
%% Be explicit to cause failure early.
@ -151,8 +151,7 @@ build2([C|Cs], Count, MaxLen) ->
build2([], _, _) -> [].
%% control(FormatChar, [Argument], FieldWidth, Adjust, Precision, PadChar,
%% Indentation) ->
%% [Char]
%% Indentation) -> [Char]
%% This is the main dispatch function for the various formatting commands.
%% Field widths and precisions have already been calculated.
@ -275,15 +274,15 @@ term(T, F, Adj, P0, Pad) ->
L = lists:flatlength(T),
P = case P0 of none -> erlang:min(L, F); _ -> P0 end,
if
L > P ->
adjust(chars($*, P), chars(Pad, F-P), Adj);
F >= P ->
adjust(T, chars(Pad, F-L), Adj)
L > P ->
adjust(chars($*, P), chars(Pad, F-P), Adj);
F >= P ->
adjust(T, chars(Pad, F-L), Adj)
end.
%% fwrite_e(Float, Field, Adjust, Precision, PadChar)
fwrite_e(Fl, none, Adj, none, Pad) -> %Default values
fwrite_e(Fl, none, Adj, none, Pad) -> %Default values
fwrite_e(Fl, none, Adj, 6, Pad);
fwrite_e(Fl, none, _Adj, P, _Pad) when P >= 2 ->
float_e(Fl, float_data(Fl), P);
@ -292,12 +291,12 @@ fwrite_e(Fl, F, Adj, none, Pad) ->
fwrite_e(Fl, F, Adj, P, Pad) when P >= 2 ->
term(float_e(Fl, float_data(Fl), P), F, Adj, F, Pad).
float_e(Fl, Fd, P) when Fl < 0.0 -> %Negative numbers
float_e(Fl, Fd, P) when Fl < 0.0 -> %Negative numbers
[$-|float_e(-Fl, Fd, P)];
float_e(_Fl, {Ds,E}, P) ->
case float_man(Ds, 1, P-1) of
{[$0|Fs],true} -> [[$1|Fs]|float_exp(E)];
{Fs,false} -> [Fs|float_exp(E-1)]
{[$0|Fs],true} -> [[$1|Fs]|float_exp(E)];
{Fs,false} -> [Fs|float_exp(E-1)]
end.
%% float_man([Digit], Icount, Dcount) -> {[Chars],CarryFlag}.
@ -310,22 +309,22 @@ float_man(Ds, 0, Dc) ->
{[$.|Cs],C};
float_man([D|Ds], I, Dc) ->
case float_man(Ds, I-1, Dc) of
{Cs,true} when D =:= $9 -> {[$0|Cs],true};
{Cs,true} -> {[D+1|Cs],false};
{Cs,false} -> {[D|Cs],false}
{Cs,true} when D =:= $9 -> {[$0|Cs],true};
{Cs,true} -> {[D+1|Cs],false};
{Cs,false} -> {[D|Cs],false}
end;
float_man([], I, Dc) -> %Pad with 0's
float_man([], I, Dc) -> %Pad with 0's
{string:chars($0, I, [$.|string:chars($0, Dc)]),false}.
float_man([D|_], 0) when D >= $5 -> {[],true};
float_man([_|_], 0) -> {[],false};
float_man([D|Ds], Dc) ->
case float_man(Ds, Dc-1) of
{Cs,true} when D =:= $9 -> {[$0|Cs],true};
{Cs,true} -> {[D+1|Cs],false};
{Cs,false} -> {[D|Cs],false}
{Cs,true} when D =:= $9 -> {[$0|Cs],true};
{Cs,true} -> {[D+1|Cs],false};
{Cs,false} -> {[D|Cs],false}
end;
float_man([], Dc) -> {string:chars($0, Dc),false}. %Pad with 0's
float_man([], Dc) -> {string:chars($0, Dc),false}. %Pad with 0's
%% float_exp(Exponent) -> [Char].
%% Generate the exponent of a floating point number. Always include sign.
@ -337,7 +336,7 @@ float_exp(E) ->
%% fwrite_f(FloatData, Field, Adjust, Precision, PadChar)
fwrite_f(Fl, none, Adj, none, Pad) -> %Default values
fwrite_f(Fl, none, Adj, none, Pad) -> %Default values
fwrite_f(Fl, none, Adj, 6, Pad);
fwrite_f(Fl, none, _Adj, P, _Pad) when P >= 1 ->
float_f(Fl, float_data(Fl), P);
@ -349,11 +348,11 @@ fwrite_f(Fl, F, Adj, P, Pad) when P >= 1 ->
float_f(Fl, Fd, P) when Fl < 0.0 ->
[$-|float_f(-Fl, Fd, P)];
float_f(Fl, {Ds,E}, P) when E =< 0 ->
float_f(Fl, {string:chars($0, -E+1, Ds),1}, P); %Prepend enough 0's
float_f(Fl, {string:chars($0, -E+1, Ds),1}, P); %Prepend enough 0's
float_f(_Fl, {Ds,E}, P) ->
case float_man(Ds, E, P) of
{Fs,true} -> "1" ++ Fs; %Handle carry
{Fs,false} -> Fs
{Fs,true} -> "1" ++ Fs; %Handle carry
{Fs,false} -> Fs
end.
%% float_data([FloatChar]) -> {[Digit],Exponent}
@ -378,20 +377,20 @@ fwrite_g(Fl, F, Adj, none, Pad) ->
fwrite_g(Fl, F, Adj, P, Pad) when P >= 1 ->
A = abs(Fl),
E = if A < 1.0e-1 -> -2;
A < 1.0e0 -> -1;
A < 1.0e1 -> 0;
A < 1.0e2 -> 1;
A < 1.0e3 -> 2;
A < 1.0e4 -> 3;
true -> fwrite_f
end,
A < 1.0e0 -> -1;
A < 1.0e1 -> 0;
A < 1.0e2 -> 1;
A < 1.0e3 -> 2;
A < 1.0e4 -> 3;
true -> fwrite_f
end,
if P =< 1, E =:= -1;
P-1 > E, E >= -1 ->
fwrite_f(Fl, F, Adj, P-1-E, Pad);
P =< 1 ->
fwrite_e(Fl, F, Adj, 2, Pad);
true ->
fwrite_e(Fl, F, Adj, P, Pad)
P-1 > E, E >= -1 ->
fwrite_f(Fl, F, Adj, P-1-E, Pad);
P =< 1 ->
fwrite_e(Fl, F, Adj, 2, Pad);
true ->
fwrite_e(Fl, F, Adj, P, Pad)
end.
@ -405,15 +404,15 @@ string(S, none, _Adj, P, Pad) ->
string(S, F, Adj, P, Pad) when F >= P ->
N = lists:flatlength(S),
if F > P ->
if N > P ->
adjust(flat_trunc(S, P), chars(Pad, F-P), Adj);
N < P ->
adjust([S|chars(Pad, P-N)], chars(Pad, F-P), Adj);
true -> % N == P
adjust(S, chars(Pad, F-P), Adj)
end;
if N > P ->
adjust(flat_trunc(S, P), chars(Pad, F-P), Adj);
N < P ->
adjust([S|chars(Pad, P-N)], chars(Pad, F-P), Adj);
true -> % N == P
adjust(S, chars(Pad, F-P), Adj)
end;
true -> % F == P
string_field(S, F, Adj, N, Pad)
string_field(S, F, Adj, N, Pad)
end.
string_field(S, F, _Adj, N, _Pad) when N > F ->
@ -429,11 +428,11 @@ string_field(S, _, _, _, _) -> % N == F
unprefixed_integer(Int, F, Adj, Base, Pad, Lowercase)
when Base >= 2, Base =< 1+$Z-$A+10 ->
if Int < 0 ->
S = cond_lowercase(erlang:integer_to_list(-Int, Base), Lowercase),
term([$-|S], F, Adj, none, Pad);
S = cond_lowercase(erlang:integer_to_list(-Int, Base), Lowercase),
term([$-|S], F, Adj, none, Pad);
true ->
S = cond_lowercase(erlang:integer_to_list(Int, Base), Lowercase),
term(S, F, Adj, none, Pad)
S = cond_lowercase(erlang:integer_to_list(Int, Base), Lowercase),
term(S, F, Adj, none, Pad)
end.
%% prefixed_integer(Int, Field, Adjust, Base, PadChar, Prefix, Lowercase)
@ -442,11 +441,11 @@ unprefixed_integer(Int, F, Adj, Base, Pad, Lowercase)
prefixed_integer(Int, F, Adj, Base, Pad, Prefix, Lowercase)
when Base >= 2, Base =< 1+$Z-$A+10 ->
if Int < 0 ->
S = cond_lowercase(erlang:integer_to_list(-Int, Base), Lowercase),
term([$-,Prefix|S], F, Adj, none, Pad);
S = cond_lowercase(erlang:integer_to_list(-Int, Base), Lowercase),
term([$-,Prefix|S], F, Adj, none, Pad);
true ->
S = cond_lowercase(erlang:integer_to_list(Int, Base), Lowercase),
term([Prefix|S], F, Adj, none, Pad)
S = cond_lowercase(erlang:integer_to_list(Int, Base), Lowercase),
term([Prefix|S], F, Adj, none, Pad)
end.
%% char(Char, Field, Adjust, Precision, PadChar) -> [Char].

+ 0
- 1
src/lager_transform.erl Dosyayı Görüntüle

@ -93,7 +93,6 @@ transform_statement({call, Line, {remote, _Line1, {atom, _Line2, lager},
[Attrs, Format, Args] ->
{concat_lists(Attrs, DefaultAttrs), Format, Args}
end,
{call, Line, {remote, Line, {atom,Line,lager},{atom,Line,dispatch_log}},
[
{atom,Line,Severity},

+ 22
- 22
src/lager_trunc_io.erl Dosyayı Görüntüle

@ -42,8 +42,8 @@
-endif.
-type option() :: {'depth', integer()}
| {'lists_as_strings', boolean()}
| {'force_strings', boolean()}.
| {'lists_as_strings', boolean()}
| {'force_strings', boolean()}.
-type options() :: [option()].
-record(print_options, {
@ -92,9 +92,9 @@ fprint(T, Max, Options) ->
-spec safe(term(), pos_integer()) -> {string(), pos_integer()} | {string()}.
safe(What, Len) ->
case catch print(What, Len) of
{L, Used} when is_list(L) -> {L, Used};
_ -> {"unable to print" ++ io_lib:write(What, 99)}
end.
{L, Used} when is_list(L) -> {L, Used};
_ -> {"unable to print" ++ io_lib:write(What, 99)}
end.
%% @doc Returns {List, Length}
-spec print(term(), pos_integer()) -> {iolist(), pos_integer()}.
@ -371,29 +371,29 @@ test() ->
-spec test(atom(), atom()) -> ok.
test(Mod, Func) ->
Simple_items = [atom, 1234, 1234.0, {tuple}, [], [list], "string", self(),
<<1,2,3>>, make_ref(), fun() -> ok end],
<<1,2,3>>, make_ref(), fun() -> ok end],
F = fun(A) ->
Mod:Func(A, 100),
Mod:Func(A, 2),
Mod:Func(A, 20)
end,
Mod:Func(A, 100),
Mod:Func(A, 2),
Mod:Func(A, 20)
end,
G = fun(A) ->
case catch F(A) of
{'EXIT', _} -> exit({failed, A});
_ -> ok
end
end,
case catch F(A) of
{'EXIT', _} -> exit({failed, A});
_ -> ok
end
end,
lists:foreach(G, Simple_items),
Tuples = [ {1,2,3,a,b,c}, {"abc", def, 1234},
{{{{a},b,c,{d},e}},f}],
{{{{a},b,c,{d},e}},f}],
Lists = [ [1,2,3,4,5,6,7], lists:seq(1,1000),
[{a}, {a,b}, {a, [b,c]}, "def"], [a|b], [$a|$b] ],
[{a}, {a,b}, {a, [b,c]}, "def"], [a|b], [$a|$b] ],
lists:foreach(G, Tuples),
lists:foreach(G, Lists).

+ 55
- 55
test/crash.erl Dosyayı Görüntüle

@ -15,92 +15,92 @@
}).
start() ->
gen_server:start({local, ?MODULE}, ?MODULE, [], []).
gen_server:start({local, ?MODULE}, ?MODULE, [], []).
init(_) ->
{ok, {}}.
{ok, {}}.
handle_call(undef, _, State) ->
{reply, ?MODULE:booger(), State};
{reply, ?MODULE:booger(), State};
handle_call(badfun, _, State) ->
M = booger,
{reply, M(), State};
M = booger,
{reply, M(), State};
handle_call(bad_return, _, _) ->
bleh;
bleh;
handle_call(bad_return_string, _, _) ->
{tuple, {tuple, "string"}};
{tuple, {tuple, "string"}};
handle_call(case_clause, _, State) ->
case State of
goober ->
{reply, ok, State}
end;
case State of
goober ->
{reply, ok, State}
end;
handle_call(case_clause_string, _, State) ->
Foo = atom_to_list(?MODULE),
case Foo of
State ->
{reply, ok, State}
end;
Foo = atom_to_list(?MODULE),
case Foo of
State ->
{reply, ok, State}
end;
handle_call(if_clause, _, State) ->
if State == 1 ->
{reply, ok, State}
end;
if State == 1 ->
{reply, ok, State}
end;
handle_call(try_clause, _, State) ->
Res = try tuple_to_list(State) of
[_A, _B] -> ok
catch
_:_ -> ok
end,
{reply, Res, State};
Res = try tuple_to_list(State) of
[_A, _B] -> ok
catch
_:_ -> ok
end,
{reply, Res, State};
handle_call(badmatch, _, State) ->
{A, B, C} = State,
{reply, [A, B, C], State};
{A, B, C} = State,
{reply, [A, B, C], State};
handle_call(badrecord, _, State) ->
Host = State#state.host,
{reply, Host, State};
Host = State#state.host,
{reply, Host, State};
handle_call(function_clause, _, State) ->
{reply, function(State), State};
{reply, function(State), State};
handle_call(badarith, _, State) ->
Res = 1 / length(tuple_to_list(State)),
{reply, Res, State};
Res = 1 / length(tuple_to_list(State)),
{reply, Res, State};
handle_call(badarg1, _, State) ->
Res = list_to_binary(["foo", bar]),
{reply, Res, State};
Res = list_to_binary(["foo", bar]),
{reply, Res, State};
handle_call(badarg2, _, State) ->
Res = erlang:iolist_to_binary(["foo", bar]),
{reply, Res, State};
Res = erlang:iolist_to_binary(["foo", bar]),
{reply, Res, State};
handle_call(system_limit, _, State) ->
Res = list_to_atom(lists:flatten(lists:duplicate(256, "a"))),
{reply, Res, State};
Res = list_to_atom(lists:flatten(lists:duplicate(256, "a"))),
{reply, Res, State};
handle_call(process_limit, _, State) ->
%% run with +P 300 to make this crash
[erlang:spawn(fun() -> timer:sleep(5000) end) || _ <- lists:seq(0, 500)],
{reply, ok, State};
%% run with +P 300 to make this crash
[erlang:spawn(fun() -> timer:sleep(5000) end) || _ <- lists:seq(0, 500)],
{reply, ok, State};
handle_call(port_limit, _, State) ->
[erlang:open_port({spawn, "ls"}, []) || _ <- lists:seq(0, 1024)],
{reply, ok, State};
[erlang:open_port({spawn, "ls"}, []) || _ <- lists:seq(0, 1024)],
{reply, ok, State};
handle_call(noproc, _, State) ->
Res = gen_event:call(foo, bar, baz),
{reply, Res, State};
Res = gen_event:call(foo, bar, baz),
{reply, Res, State};
handle_call(badarity, _, State) ->
F = fun(A, B, C) -> A + B + C end,
Res = F(State),
{reply, Res, State};
F = fun(A, B, C) -> A + B + C end,
Res = F(State),
{reply, Res, State};
handle_call(throw, _, _State) ->
throw(a_ball);
throw(a_ball);
handle_call(_Call, _From, State) ->
{reply, ok, State}.
{reply, ok, State}.
handle_cast(_Cast, State) ->
{noreply, State}.
{noreply, State}.
handle_info(_Info, State) ->
{noreply, State}.
{noreply, State}.
terminate(_, _) ->
ok.
ok.
code_change(_, State, _) ->
{ok, State}.
{ok, State}.
function(X) when is_list(X) ->
ok.
ok.

Yükleniyor…
İptal
Kaydet