|
|
@ -184,168 +184,168 @@ log_event(Event, #state{sink = Sink} = State) -> |
|
|
|
{Md, Formatted} = format_reason_md(Reason), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid}, {name, Name} | Md], "gen_server ~w terminated with reason: ~s", |
|
|
|
[Name, Formatted]); |
|
|
|
{false, "** State machine " ++ _} -> |
|
|
|
%% Check if the terminated process is gen_fsm or gen_statem |
|
|
|
%% since they generate the same exit message |
|
|
|
{Type, Name, StateName, Reason} = |
|
|
|
case Args of |
|
|
|
[TName, _Msg, TStateName, _StateData, TReason] -> |
|
|
|
{gen_fsm, TName, TStateName, TReason}; |
|
|
|
%% Handle changed logging in gen_fsm stdlib-3.9 (TPid, ClientArgs) |
|
|
|
[TName, _Msg, TPid, TStateName, _StateData, TReason | _ClientArgs] when is_pid(TPid), is_atom(TStateName) -> |
|
|
|
{gen_fsm, TName, TStateName, TReason}; |
|
|
|
%% Handle changed logging in gen_statem stdlib-3.9 (ClientArgs) |
|
|
|
[TName, _Msg, {TStateName, _StateData}, _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> |
|
|
|
{gen_statem, TName, TStateName, {TReason, Stacktrace}}; |
|
|
|
%% Handle changed logging in gen_statem stdlib-3.9 (ClientArgs) |
|
|
|
[TName, {TStateName, _StateData}, _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> |
|
|
|
{gen_statem, TName, TStateName, {TReason, Stacktrace}}; |
|
|
|
[TName, _Msg, [{TStateName, _StateData}], _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> |
|
|
|
%% sometimes gen_statem wraps its statename/data in a list for some reason??? |
|
|
|
{gen_statem, TName, TStateName, {TReason, Stacktrace}} |
|
|
|
end, |
|
|
|
{Md, Formatted} = format_reason_md(Reason), |
|
|
|
?CRASH_LOG(Event), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid}, {name, Name} | Md], "~s ~w in state ~w terminated with reason: ~s", |
|
|
|
[Type, Name, StateName, Formatted]); |
|
|
|
{false, "** gen_event handler" ++ _} -> |
|
|
|
%% gen_event handler terminate |
|
|
|
[ID, Name, _Msg, _State, Reason] = Args, |
|
|
|
{false, "** State machine " ++ _} -> |
|
|
|
%% Check if the terminated process is gen_fsm or gen_statem |
|
|
|
%% since they generate the same exit message |
|
|
|
{Type, Name, StateName, Reason} = |
|
|
|
case Args of |
|
|
|
[TName, _Msg, TStateName, _StateData, TReason] -> |
|
|
|
{gen_fsm, TName, TStateName, TReason}; |
|
|
|
%% Handle changed logging in gen_fsm stdlib-3.9 (TPid, ClientArgs) |
|
|
|
[TName, _Msg, TPid, TStateName, _StateData, TReason | _ClientArgs] when is_pid(TPid), is_atom(TStateName) -> |
|
|
|
{gen_fsm, TName, TStateName, TReason}; |
|
|
|
%% Handle changed logging in gen_statem stdlib-3.9 (ClientArgs) |
|
|
|
[TName, _Msg, {TStateName, _StateData}, _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> |
|
|
|
{gen_statem, TName, TStateName, {TReason, Stacktrace}}; |
|
|
|
%% Handle changed logging in gen_statem stdlib-3.9 (ClientArgs) |
|
|
|
[TName, {TStateName, _StateData}, _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> |
|
|
|
{gen_statem, TName, TStateName, {TReason, Stacktrace}}; |
|
|
|
[TName, _Msg, [{TStateName, _StateData}], _ExitType, TReason, _CallbackMode, Stacktrace | _ClientArgs] -> |
|
|
|
%% sometimes gen_statem wraps its statename/data in a list for some reason??? |
|
|
|
{gen_statem, TName, TStateName, {TReason, Stacktrace}} |
|
|
|
end, |
|
|
|
{Md, Formatted} = format_reason_md(Reason), |
|
|
|
?CRASH_LOG(Event), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid}, {name, Name} | Md], "~s ~w in state ~w terminated with reason: ~s", |
|
|
|
[Type, Name, StateName, Formatted]); |
|
|
|
{false, "** gen_event handler" ++ _} -> |
|
|
|
%% gen_event handler terminate |
|
|
|
[ID, Name, _Msg, _State, Reason] = Args, |
|
|
|
{Md, Formatted} = format_reason_md(Reason), |
|
|
|
?CRASH_LOG(Event), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid}, {name, Name} | Md], "gen_event ~w installed in ~w terminated with reason: ~s", |
|
|
|
[ID, Name, Formatted]); |
|
|
|
{false, "** Cowboy handler" ++ _} -> |
|
|
|
%% Cowboy HTTP server error |
|
|
|
?CRASH_LOG(Event), |
|
|
|
case Args of |
|
|
|
[Module, Function, Arity, _Request, _State] -> |
|
|
|
%% we only get the 5-element list when its a non-exported function |
|
|
|
?LOGFMT(Sink, error, Pid, |
|
|
|
"Cowboy handler ~p terminated with reason: call to undefined function ~p:~p/~p", |
|
|
|
[Module, Module, Function, Arity]); |
|
|
|
[Module, Function, Arity, _Class, Reason | Tail] -> |
|
|
|
%% any other cowboy error_format list *always* ends with the stacktrace |
|
|
|
StackTrace = lists:last(Tail), |
|
|
|
{Md, Formatted} = format_reason_md({Reason, StackTrace}), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid} | Md], |
|
|
|
"Cowboy handler ~p terminated in ~p:~p/~p with reason: ~s", |
|
|
|
[Module, Module, Function, Arity, Formatted]) |
|
|
|
end; |
|
|
|
{false, "Ranch listener " ++ _} -> |
|
|
|
%% Ranch errors |
|
|
|
?CRASH_LOG(Event), |
|
|
|
case Args of |
|
|
|
%% Error logged by cowboy, which starts as ranch error |
|
|
|
[Ref, ConnectionPid, StreamID, RequestPid, Reason, StackTrace] -> |
|
|
|
{Md, Formatted} = format_reason_md({Reason, StackTrace}), |
|
|
|
?LOGFMT(Sink, error, [{pid, RequestPid} | Md], |
|
|
|
"Cowboy stream ~p with ranch listener ~p and connection process ~p " |
|
|
|
"had its request process exit with reason: ~s", |
|
|
|
[StreamID, Ref, ConnectionPid, Formatted]); |
|
|
|
[Ref, _Protocol, Worker, {[{reason, Reason}, {mfa, {Module, Function, Arity}}, {stacktrace, StackTrace} | _], _}] -> |
|
|
|
{Md, Formatted} = format_reason_md({Reason, StackTrace}), |
|
|
|
?LOGFMT(Sink, error, [{pid, Worker} | Md], |
|
|
|
"Ranch listener ~p terminated in ~p:~p/~p with reason: ~s", |
|
|
|
[Ref, Module, Function, Arity, Formatted]); |
|
|
|
[Ref, _Protocol, Worker, Reason] -> |
|
|
|
{Md, Formatted} = format_reason_md(Reason), |
|
|
|
?CRASH_LOG(Event), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid}, {name, Name} | Md], "gen_event ~w installed in ~w terminated with reason: ~s", |
|
|
|
[ID, Name, Formatted]); |
|
|
|
{false, "** Cowboy handler" ++ _} -> |
|
|
|
%% Cowboy HTTP server error |
|
|
|
?CRASH_LOG(Event), |
|
|
|
case Args of |
|
|
|
[Module, Function, Arity, _Request, _State] -> |
|
|
|
%% we only get the 5-element list when its a non-exported function |
|
|
|
?LOGFMT(Sink, error, Pid, |
|
|
|
"Cowboy handler ~p terminated with reason: call to undefined function ~p:~p/~p", |
|
|
|
[Module, Module, Function, Arity]); |
|
|
|
[Module, Function, Arity, _Class, Reason | Tail] -> |
|
|
|
%% any other cowboy error_format list *always* ends with the stacktrace |
|
|
|
StackTrace = lists:last(Tail), |
|
|
|
{Md, Formatted} = format_reason_md({Reason, StackTrace}), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid} | Md], |
|
|
|
"Cowboy handler ~p terminated in ~p:~p/~p with reason: ~s", |
|
|
|
[Module, Module, Function, Arity, Formatted]) |
|
|
|
end; |
|
|
|
{false, "Ranch listener " ++ _} -> |
|
|
|
%% Ranch errors |
|
|
|
?CRASH_LOG(Event), |
|
|
|
case Args of |
|
|
|
%% Error logged by cowboy, which starts as ranch error |
|
|
|
[Ref, ConnectionPid, StreamID, RequestPid, Reason, StackTrace] -> |
|
|
|
{Md, Formatted} = format_reason_md({Reason, StackTrace}), |
|
|
|
?LOGFMT(Sink, error, [{pid, RequestPid} | Md], |
|
|
|
"Cowboy stream ~p with ranch listener ~p and connection process ~p " |
|
|
|
"had its request process exit with reason: ~s", |
|
|
|
[StreamID, Ref, ConnectionPid, Formatted]); |
|
|
|
[Ref, _Protocol, Worker, {[{reason, Reason}, {mfa, {Module, Function, Arity}}, {stacktrace, StackTrace} | _], _}] -> |
|
|
|
{Md, Formatted} = format_reason_md({Reason, StackTrace}), |
|
|
|
?LOGFMT(Sink, error, [{pid, Worker} | Md], |
|
|
|
"Ranch listener ~p terminated in ~p:~p/~p with reason: ~s", |
|
|
|
[Ref, Module, Function, Arity, Formatted]); |
|
|
|
[Ref, _Protocol, Worker, Reason] -> |
|
|
|
{Md, Formatted} = format_reason_md(Reason), |
|
|
|
?LOGFMT(Sink, error, [{pid, Worker} | Md], |
|
|
|
"Ranch listener ~p terminated with reason: ~s", |
|
|
|
[Ref, Formatted]); |
|
|
|
[Ref, Protocol, Ret] -> |
|
|
|
%% ranch_conns_sup.erl module line 119-123 has three parameters error msg, log it. |
|
|
|
{Md, Formatted} = format_reason_md(Ret), |
|
|
|
?LOGFMT(Sink, error, [{pid, Protocol} | Md], |
|
|
|
"Ranch listener ~p terminated with result:~s", |
|
|
|
[Ref, Formatted]) |
|
|
|
end; |
|
|
|
{false, "webmachine error" ++ _} -> |
|
|
|
%% Webmachine HTTP server error |
|
|
|
?CRASH_LOG(Event), |
|
|
|
[Path, Error] = Args, |
|
|
|
%% webmachine likes to mangle the stack, for some reason |
|
|
|
StackTrace = case Error of |
|
|
|
{error, {error, Reason, Stack}} -> |
|
|
|
{Reason, Stack}; |
|
|
|
_ -> |
|
|
|
Error |
|
|
|
end, |
|
|
|
{Md, Formatted} = format_reason_md(StackTrace), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid} | Md], "Webmachine error at path ~p : ~s", [Path, Formatted]); |
|
|
|
_ -> |
|
|
|
?CRASH_LOG(Event), |
|
|
|
?LOGFMT(Sink, error, Pid, Fmt, Args) |
|
|
|
?LOGFMT(Sink, error, [{pid, Worker} | Md], |
|
|
|
"Ranch listener ~p terminated with reason: ~s", |
|
|
|
[Ref, Formatted]); |
|
|
|
[Ref, Protocol, Ret] -> |
|
|
|
%% ranch_conns_sup.erl module line 119-123 has three parameters error msg, log it. |
|
|
|
{Md, Formatted} = format_reason_md(Ret), |
|
|
|
?LOGFMT(Sink, error, [{pid, Protocol} | Md], |
|
|
|
"Ranch listener ~p terminated with result:~s", |
|
|
|
[Ref, Formatted]) |
|
|
|
end; |
|
|
|
{error_report, _GL, {Pid, std_error, D}} -> |
|
|
|
{false, "webmachine error" ++ _} -> |
|
|
|
%% Webmachine HTTP server error |
|
|
|
?CRASH_LOG(Event), |
|
|
|
?LOGMSG(Sink, error, Pid, print_silly_list(D)); |
|
|
|
{error_report, _GL, {Pid, supervisor_report, D}} -> |
|
|
|
[Path, Error] = Args, |
|
|
|
%% webmachine likes to mangle the stack, for some reason |
|
|
|
StackTrace = case Error of |
|
|
|
{error, {error, Reason, Stack}} -> |
|
|
|
{Reason, Stack}; |
|
|
|
_ -> |
|
|
|
Error |
|
|
|
end, |
|
|
|
{Md, Formatted} = format_reason_md(StackTrace), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid} | Md], "Webmachine error at path ~p : ~s", [Path, Formatted]); |
|
|
|
_ -> |
|
|
|
?CRASH_LOG(Event), |
|
|
|
case lists:sort(D) of |
|
|
|
[{errorContext, Ctx}, {offender, Off}, {reason, Reason}, {supervisor, Name}] -> |
|
|
|
Offender = format_offender(Off), |
|
|
|
{Md, Formatted} = format_reason_md(Reason), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid} | Md], |
|
|
|
"Supervisor ~w had child ~s exit with reason ~s in context ~w", |
|
|
|
[supervisor_name(Name), Offender, Formatted, Ctx]); |
|
|
|
?LOGFMT(Sink, error, Pid, Fmt, Args) |
|
|
|
end; |
|
|
|
{error_report, _GL, {Pid, std_error, D}} -> |
|
|
|
?CRASH_LOG(Event), |
|
|
|
?LOGMSG(Sink, error, Pid, print_silly_list(D)); |
|
|
|
{error_report, _GL, {Pid, supervisor_report, D}} -> |
|
|
|
?CRASH_LOG(Event), |
|
|
|
case lists:sort(D) of |
|
|
|
[{errorContext, Ctx}, {offender, Off}, {reason, Reason}, {supervisor, Name}] -> |
|
|
|
Offender = format_offender(Off), |
|
|
|
{Md, Formatted} = format_reason_md(Reason), |
|
|
|
?LOGFMT(Sink, error, [{pid, Pid} | Md], |
|
|
|
"Supervisor ~w had child ~s exit with reason ~s in context ~w", |
|
|
|
[supervisor_name(Name), Offender, Formatted, Ctx]); |
|
|
|
_ -> |
|
|
|
?LOGMSG(Sink, error, Pid, "SUPERVISOR REPORT " ++ print_silly_list(D)) |
|
|
|
end; |
|
|
|
{error_report, _GL, {Pid, crash_report, [Self, Neighbours]}} -> |
|
|
|
?CRASH_LOG(Event), |
|
|
|
{Md, Formatted} = format_crash_report(Self, Neighbours), |
|
|
|
?LOGMSG(Sink, error, [{pid, Pid} | Md], "CRASH REPORT " ++ Formatted); |
|
|
|
{warning_msg, _GL, {Pid, Fmt, Args}} -> |
|
|
|
?LOGFMT(Sink, warning, Pid, Fmt, Args); |
|
|
|
{warning_report, _GL, {Pid, std_warning, Report}} -> |
|
|
|
?LOGMSG(Sink, warning, Pid, print_silly_list(Report)); |
|
|
|
{info_msg, _GL, {Pid, Fmt, Args}} -> |
|
|
|
?LOGFMT(Sink, info, Pid, Fmt, Args); |
|
|
|
{info_report, _GL, {Pid, std_info, D}} when is_list(D) -> |
|
|
|
Details = lists:sort(D), |
|
|
|
case Details of |
|
|
|
[{application, App}, {exited, Reason}, {type, _Type}] -> |
|
|
|
case application:get_env(lager, suppress_application_start_stop, false) of |
|
|
|
true when Reason == stopped -> |
|
|
|
no_log; |
|
|
|
_ -> |
|
|
|
?LOGMSG(Sink, error, Pid, "SUPERVISOR REPORT " ++ print_silly_list(D)) |
|
|
|
{Md, Formatted} = format_reason_md(Reason), |
|
|
|
?LOGFMT(Sink, info, [{pid, Pid} | Md], "Application ~w exited with reason: ~s", |
|
|
|
[App, Formatted]) |
|
|
|
end; |
|
|
|
{error_report, _GL, {Pid, crash_report, [Self, Neighbours]}} -> |
|
|
|
?CRASH_LOG(Event), |
|
|
|
{Md, Formatted} = format_crash_report(Self, Neighbours), |
|
|
|
?LOGMSG(Sink, error, [{pid, Pid} | Md], "CRASH REPORT " ++ Formatted); |
|
|
|
{warning_msg, _GL, {Pid, Fmt, Args}} -> |
|
|
|
?LOGFMT(Sink, warning, Pid, Fmt, Args); |
|
|
|
{warning_report, _GL, {Pid, std_warning, Report}} -> |
|
|
|
?LOGMSG(Sink, warning, Pid, print_silly_list(Report)); |
|
|
|
{info_msg, _GL, {Pid, Fmt, Args}} -> |
|
|
|
?LOGFMT(Sink, info, Pid, Fmt, Args); |
|
|
|
{info_report, _GL, {Pid, std_info, D}} when is_list(D) -> |
|
|
|
Details = lists:sort(D), |
|
|
|
case Details of |
|
|
|
[{application, App}, {exited, Reason}, {type, _Type}] -> |
|
|
|
case application:get_env(lager, suppress_application_start_stop, false) of |
|
|
|
true when Reason == stopped -> |
|
|
|
no_log; |
|
|
|
_ -> |
|
|
|
{Md, Formatted} = format_reason_md(Reason), |
|
|
|
?LOGFMT(Sink, info, [{pid, Pid} | Md], "Application ~w exited with reason: ~s", |
|
|
|
[App, Formatted]) |
|
|
|
end; |
|
|
|
_ -> |
|
|
|
?LOGMSG(Sink, info, Pid, print_silly_list(D)) |
|
|
|
end; |
|
|
|
{info_report, _GL, {Pid, std_info, D}} -> |
|
|
|
?LOGFMT(Sink, info, Pid, "~w", [D]); |
|
|
|
{info_report, _GL, {P, progress, D}} -> |
|
|
|
Details = lists:sort(D), |
|
|
|
case Details of |
|
|
|
[{application, App}, {started_at, Node}] -> |
|
|
|
case application:get_env(lager, suppress_application_start_stop, false) of |
|
|
|
true -> |
|
|
|
no_log; |
|
|
|
_ -> |
|
|
|
?LOGMSG(Sink, info, Pid, print_silly_list(D)) |
|
|
|
?LOGFMT(Sink, info, P, "Application ~w started on node ~w", |
|
|
|
[App, Node]) |
|
|
|
end; |
|
|
|
{info_report, _GL, {Pid, std_info, D}} -> |
|
|
|
?LOGFMT(Sink, info, Pid, "~w", [D]); |
|
|
|
{info_report, _GL, {P, progress, D}} -> |
|
|
|
Details = lists:sort(D), |
|
|
|
case Details of |
|
|
|
[{application, App}, {started_at, Node}] -> |
|
|
|
case application:get_env(lager, suppress_application_start_stop, false) of |
|
|
|
true -> |
|
|
|
no_log; |
|
|
|
_ -> |
|
|
|
?LOGFMT(Sink, info, P, "Application ~w started on node ~w", |
|
|
|
[App, Node]) |
|
|
|
end; |
|
|
|
[{started, Started}, {supervisor, Name}] -> |
|
|
|
case application:get_env(lager, suppress_supervisor_start_stop, false) of |
|
|
|
true -> |
|
|
|
no_log; |
|
|
|
_ -> |
|
|
|
MFA = format_mfa(get_value(mfargs, Started)), |
|
|
|
Pid = get_value(pid, Started), |
|
|
|
?LOGFMT(Sink, debug, P, "Supervisor ~w started ~s at pid ~w", |
|
|
|
[supervisor_name(Name), MFA, Pid]) |
|
|
|
end; |
|
|
|
[{started, Started}, {supervisor, Name}] -> |
|
|
|
case application:get_env(lager, suppress_supervisor_start_stop, false) of |
|
|
|
true -> |
|
|
|
no_log; |
|
|
|
_ -> |
|
|
|
?LOGMSG(Sink, info, P, "PROGRESS REPORT " ++ print_silly_list(D)) |
|
|
|
MFA = format_mfa(get_value(mfargs, Started)), |
|
|
|
Pid = get_value(pid, Started), |
|
|
|
?LOGFMT(Sink, debug, P, "Supervisor ~w started ~s at pid ~w", |
|
|
|
[supervisor_name(Name), MFA, Pid]) |
|
|
|
end; |
|
|
|
_ -> |
|
|
|
?LOGFMT(Sink, warning, self(), "Unexpected error_logger event ~w", [Event]) |
|
|
|
end, |
|
|
|
?LOGMSG(Sink, info, P, "PROGRESS REPORT " ++ print_silly_list(D)) |
|
|
|
end; |
|
|
|
_ -> |
|
|
|
?LOGFMT(Sink, warning, self(), "Unexpected error_logger event ~w", [Event]) |
|
|
|
end, |
|
|
|
case DidLog of |
|
|
|
logged -> |
|
|
|
{ok, State}; |
|
|
|