Skip to content
Browse files

Prettyprint webmachine and cowboy error_logger messages

  • Loading branch information...
1 parent 2a8706b commit 9e5371a6966ebcbdf97b7ecb43bd78035860e736 @Vagabond Vagabond committed Dec 13, 2012
Showing with 28 additions and 0 deletions.
  1. +28 −0 src/error_logger_lager_h.erl
View
28 src/error_logger_lager_h.erl
@@ -86,6 +86,34 @@ handle_event(Event, State) ->
?CRASH_LOG(Event),
?LOGFMT(error, Pid, "gen_event ~w installed in ~w terminated with reason: ~s",
[ID, Name, format_reason(Reason)]);
+ "** 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(error, Pid,
+ "Cowboy handler ~p terminated with reason: call to undefined function ~p:~p/~p",
+ [Module, Module, Function, Arity]);
+ [Module, Function, Arity | Tail] ->
+ %% any other cowboy error_format list *always* ends with the stacktrace
+ StackTrace = lists:last(Tail),
+ ?LOGFMT(error, Pid,
+ "Cowboy handler ~p terminated in ~p:~p/~p with reason: ~s",
+ [Module, Module, Function, Arity, format_reason(StackTrace)])
+ end;
+ "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,
+ ?LOGFMT(error, Pid, "Webmachine error at path ~p : ~s", [Path, format_reason(StackTrace)]);
_ ->
?CRASH_LOG(Event),
?LOGMSG(error, Pid, lager:safe_format(Fmt, Args, ?DEFAULT_TRUNCATION))

0 comments on commit 9e5371a

Please sign in to comment.
Something went wrong with that request. Please try again.