diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index 2ef8887..72ff9d9 100644 --- a/src/error_logger_lager_h.erl +++ b/src/error_logger_lager_h.erl @@ -244,6 +244,13 @@ log_event(Event, #state{sink=Sink} = State) -> %% 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], diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index 955ca53..cb4a520 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -1648,6 +1648,26 @@ error_logger_redirect_test_() -> ?assertEqual("Cowboy handler my_handler terminated with reason: call to undefined function my_handler:to_json/2", lists:flatten(Msg)) end }, + {"Cowboy error reports, 6 arg version", + fun(Sink) -> + Stack = [{app_http, init, 2, [{file, "app_http.erl"}, {line,9}]}, + {cowboy_handler, execute, 2, [{file, "cowboy_handler.erl"}, {line, 41}]}], + ConnectionPid = list_to_pid("<0.82.0>"), + sync_error_logger:error_msg( + "Ranch listener ~p, connection process ~p, stream ~p " + "had its request process ~p exit with reason " + "~999999p and stacktrace ~999999p~n", + [my_listner, ConnectionPid, 1, self(), {badmatch, 2}, Stack]), + _ = gen_event:which_handlers(error_logger), + {Level, _, Msg, Metadata} = pop(Sink), + ?assertEqual(lager_util:level_to_num(error), Level), + ?assertEqual(self(), proplists:get_value(pid, Metadata)), + ?assertEqual("Cowboy stream 1 with ranch listener my_listner and " + "connection process <0.82.0> had its request process exit " + "with reason: no match of right hand value 2 " + "in app_http:init/2 line 9", lists:flatten(Msg)) + end + }, {"messages should not be generated if they don't satisfy the threshold", fun(Sink) -> lager:set_loglevel(Sink, ?MODULE, undefined, error),