Quellcode durchsuchen

Optimize list construction, somewhat

pull/4/head
Andrew Thompson vor 14 Jahren
Ursprung
Commit
10153cff92
2 geänderte Dateien mit 24 neuen und 26 gelöschten Zeilen
  1. +16
    -16
      src/error_logger_lager_h.erl
  2. +8
    -10
      src/lager.erl

+ 16
- 16
src/error_logger_lager_h.erl Datei anzeigen

@ -74,10 +74,10 @@ handle_event(Event, State) ->
Offender = format_offender(Off),
?LOG(error, Pid, "Supervisor ~w had child ~s exit with reason ~w in context ~w", [element(2, Name), Offender, Reason, Ctx]);
_ ->
?LOG(error, Pid, "SUPERVISOR REPORT " ++ print_silly_list(D))
?LOG(error, Pid, ["SUPERVISOR REPORT ", print_silly_list(D)])
end;
{error_report, _GL, {Pid, crash_report, [Self, Neighbours]}} ->
?LOG(error, Pid, "CRASH REPORT " ++ format_crash_report(Self, Neighbours));
?LOG(error, Pid, ["CRASH REPORT ", format_crash_report(Self, Neighbours)]);
{info_msg, _GL, {Pid, Fmt, Args}} ->
?LOG(info, Pid, Fmt, Args);
{info_report, _GL, {Pid, std_info, D}} ->
@ -99,7 +99,7 @@ handle_event(Event, State) ->
Pid = proplists:get_value(pid, Started),
?LOG(info, P, "Supervisor ~w started ~s at pid ~w", [element(2, Name), MFA, Pid]);
_ ->
?LOG(info, P, "PROGRESS REPORT " ++ print_silly_list(D))
?LOG(info, P, ["PROGRESS REPORT ", print_silly_list(D)])
end;
_ ->
io:format("Event ~w~n", [Event])
@ -134,39 +134,39 @@ format_offender(Off) ->
end.
format_reason({'function not exported', [{M, F, A},MFA|_]}) ->
"call to undefined function " ++ format_mfa({M, F, length(A)}) ++ " from " ++ format_mfa(MFA);
["call to undefined function ", format_mfa({M, F, length(A)}), " from ", format_mfa(MFA)];
format_reason({undef, [MFA|_]}) ->
"call to undefined function " ++ format_mfa(MFA);
["call to undefined function ", format_mfa(MFA)];
format_reason({bad_return_value, Val}) ->
io_lib:format("bad return value: ~w", [Val]);
format_reason({{case_clause, Val}, [MFA|_]}) ->
io_lib:format("no case clause matching ~w in ", [Val]) ++ format_mfa(MFA);
[io_lib:format("no case clause matching ~w in ", [Val]), format_mfa(MFA)];
format_reason({function_clause, [MFA|_]}) ->
"no function clause matching " ++ format_mfa(MFA);
["no function clause matching ", format_mfa(MFA)];
format_reason({if_clause, [MFA|_]}) ->
"no true branch found while evaluating if expression in " ++ format_mfa(MFA);
["no true branch found while evaluating if expression in ", format_mfa(MFA)];
format_reason({{try_clause, Val}, [MFA|_]}) ->
io_lib:format("no try clause matching ~w in ", [Val]) ++ format_mfa(MFA);
[io_lib:format("no try clause matching ~w in ", [Val]), format_mfa(MFA)];
format_reason({badarith, [MFA|_]}) ->
"bad arithmetic expression in " ++ format_mfa(MFA);
["bad arithmetic expression in ", format_mfa(MFA)];
format_reason({{badmatch, Val}, [MFA|_]}) ->
io_lib:format("no match of right hand value ~w in ", [Val]) ++ format_mfa(MFA);
[io_lib:format("no match of right hand value ~w in ", [Val]), format_mfa(MFA)];
%format_reason({system_limit,
format_reason({badarg, [MFA,MFA2|_]}) ->
case MFA of
{_M, _F, A} when is_list(A) ->
"bad argument in call to " ++ format_mfa(MFA) ++ " in " ++ format_mfa(MFA2);
["bad argument in call to ", format_mfa(MFA), " in ", format_mfa(MFA2)];
_ ->
%% seems to be generated by a bad call to a BIF
"bad argument in " ++ format_mfa(MFA)
["bad argument in ", format_mfa(MFA)]
end;
format_reason({{badarity, {Fun, Args}}, [MFA|_]}) ->
{arity, Arity} = lists:keyfind(arity, 1, erlang:fun_info(Fun)),
io_lib:format("fun called with wrong arity of ~w instead of ~w in ", [length(Args), Arity]) ++ format_mfa(MFA);
[io_lib:format("fun called with wrong arity of ~w instead of ~w in ", [length(Args), Arity]), format_mfa(MFA)];
format_reason({noproc, MFA}) ->
"no such process or port in call to " ++ format_mfa(MFA);
["no such process or port in call to ", format_mfa(MFA)];
format_reason({{badfun, Term}, [MFA|_]}) ->
io_lib:format("bad function ~w in ", [Term]) ++ format_mfa(MFA);
[io_lib:format("bad function ~w in ", [Term]), format_mfa(MFA)];
format_reason(Reason) ->
{Str, _} = trunc_io:print(Reason, 500),
Str.

+ 8
- 10
src/lager.erl Datei anzeigen

@ -32,9 +32,6 @@
%% API
start_link() ->
%application:start(sasl),
%application:set_env(riak_err, print_fun, {lager, sasl_log}),
%application:start(riak_err),
Handlers = case application:get_env(lager, handlers) of
undefined ->
[{lager_console_backend, [info]},
@ -56,27 +53,27 @@ start() ->
log(Level, Module, Function, Line, Pid, {{Y, M, D}, {H, Mi, S}}, Message) ->
Time = io_lib:format("~b-~b-~b ~b:~b:~b", [Y, M, D, H, Mi, S]),
Msg = io_lib:format("[~p] ~p@~p:~p:~p ~s", [Level, Pid, Module,
Function, Line, Message]),
Msg = [io_lib:format("[~p] ~p@~p:~p:~p ", [Level, Pid, Module,
Function, Line]), Message],
gen_event:sync_notify(lager_event, {log, lager_util:level_to_num(Level), Time, Msg}).
log(Level, Module, Function, Line, Pid, {{Y, M, D}, {H, Mi, S}}, Format, Args) ->
Time = io_lib:format("~b-~b-~b ~b:~b:~b", [Y, M, D, H, Mi, S]),
Msg = io_lib:format("[~p] ~p@~p:~p:~p ~s", [Level, Pid, Module,
Function, Line, io_lib:format(Format, Args)]),
Msg = [io_lib:format("[~p] ~p@~p:~p:~p ", [Level, Pid, Module,
Function, Line]), io_lib:format(Format, Args)],
gen_event:sync_notify(lager_event, {log, lager_util:level_to_num(Level), Time, Msg}).
log(Level, Pid, Message) ->
{{Y, M, D}, {H, Mi, S}} = lager_stdlib:maybe_utc(erlang:localtime()),
Time = io_lib:format("~b-~b-~b ~b:~b:~b", [Y, M, D, H, Mi, S]),
Msg = io_lib:format("[~p] ~p ~s", [Level, Pid, Message]),
Msg = [io_lib:format("[~p] ~p ", [Level, Pid]), Message],
gen_event:sync_notify(lager_event, {log, lager_util:level_to_num(Level),
Time, Msg}).
log(Level, Pid, Format, Args) ->
{{Y, M, D}, {H, Mi, S}} = lager_stdlib:maybe_utc(erlang:localtime()),
Time = io_lib:format("~b-~b-~b ~b:~b:~b", [Y, M, D, H, Mi, S]),
Msg = io_lib:format("[~p] ~p ~s", [Level, Pid, io_lib:format(Format, Args)]),
Msg = [io_lib:format("[~p] ~p ", [Level, Pid]), io_lib:format(Format, Args)],
gen_event:sync_notify(lager_event, {log, lager_util:level_to_num(Level),
Time, Msg}).
@ -135,7 +132,8 @@ handle_cast(_Request, State) ->
{noreply, State}.
handle_info({gen_event_EXIT, error_logger_lager_h, {'EXIT', Reason}}, State) ->
lager:log(error, self(), ["Restarting lager error handler after it exited with ", error_logger_lager_h:format_reason(Reason)]),
lager:log(error, self(), ["Restarting lager error handler after it exited with ",
error_logger_lager_h:format_reason(Reason)]),
gen_event:add_sup_handler(error_logger, error_logger_lager_h, []),
{noreply, State};
handle_info(Info, State) ->

Laden…
Abbrechen
Speichern