Pārlūkot izejas kodu

Merge pull request #485 from velimir0xff/cowboy-stream-process-error

Handle errors generated by cowboy which were treated as ranch errors
pull/486/head
Mark Allen pirms 6 gadiem
revīziju iesūtīja GitHub
vecāks
revīzija
ecb78c54cf
Šim parakstam datu bāzē netika atrasta zināma atslēga GPG atslēgas ID: 4AEE18F83AFDEB23
2 mainītis faili ar 27 papildinājumiem un 0 dzēšanām
  1. +7
    -0
      src/error_logger_lager_h.erl
  2. +20
    -0
      test/lager_test_backend.erl

+ 7
- 0
src/error_logger_lager_h.erl Parādīt failu

@ -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],

+ 20
- 0
test/lager_test_backend.erl Parādīt failu

@ -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),

Notiek ielāde…
Atcelt
Saglabāt