From 9e5371a6966ebcbdf97b7ecb43bd78035860e736 Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 13 Dec 2012 03:51:10 -0500 Subject: [PATCH] Prettyprint webmachine and cowboy error_logger messages --- src/error_logger_lager_h.erl | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index a9efce8..2fc5357 100644 --- a/src/error_logger_lager_h.erl +++ b/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))