couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [31/50] chttpd commit: updated refs/heads/master to 58020ab
Date Thu, 28 Aug 2014 11:59:54 GMT
Improve logging of errors with traces


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/50ccf293
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/50ccf293
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/50ccf293

Branch: refs/heads/master
Commit: 50ccf2932b9072fefd24111c3b6fb7d54038a8cd
Parents: f4b0fdc
Author: Robert Newson <robert.newson@cloudant.com>
Authored: Tue Dec 10 00:44:04 2013 +0000
Committer: Robert Newson <rnewson@apache.org>
Committed: Thu Jul 31 11:54:27 2014 +0100

----------------------------------------------------------------------
 src/chttpd.erl | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/50ccf293/src/chttpd.erl
----------------------------------------------------------------------
diff --git a/src/chttpd.erl b/src/chttpd.erl
index 93b56f0..372a61d 100644
--- a/src/chttpd.erl
+++ b/src/chttpd.erl
@@ -642,7 +642,7 @@ send_delayed_error(#delayed_resp{req=Req,resp=nil}=DelayedResp, Reason)
->
     {ok, Resp} = send_error(Req, Code, ErrorStr, ReasonStr),
     {ok, DelayedResp#delayed_resp{resp=Resp}};
 send_delayed_error(#delayed_resp{resp=Resp}, Reason) ->
-    log_stack_trace(json_stack(Reason)),
+    log_error_with_stack_trace(Reason),
     throw({http_abort, Resp, Reason}).
 
 end_delayed_json_response(#delayed_resp{}=DelayedResp) ->
@@ -813,11 +813,11 @@ send_error(Req, Code, Headers, ErrorStr, ReasonStr, []) ->
         {[{<<"error">>,  ErrorStr},
         {<<"reason">>, ReasonStr}]});
 send_error(Req, Code, Headers, ErrorStr, ReasonStr, Stack) ->
-    log_stack_trace(Stack),
+    log_error_with_stack_trace({ErrorStr, ReasonStr, Stack}),
     send_json(Req, Code, [stack_trace_id(Stack) | Headers],
         {[{<<"error">>,  ErrorStr},
-        {<<"reason">>, ReasonStr},
-        {<<"ref">>, stack_hash(Stack)}
+        {<<"reason">>, ReasonStr} |
+        case Stack of [] -> []; _ -> [{<<"ref">>, stack_hash(Stack)}] end
     ]}).
 
 % give the option for list functions to output html or other raw errors
@@ -827,12 +827,12 @@ send_chunked_error(Resp, {_Error, {[{<<"body">>, Reason}]}})
->
 
 send_chunked_error(Resp, Error) ->
     Stack = json_stack(Error),
-    log_stack_trace(Stack),
+    log_error_with_stack_trace(Error),
     {Code, ErrorStr, ReasonStr} = error_info(Error),
     JsonError = {[{<<"code">>, Code},
         {<<"error">>,  ErrorStr},
-        {<<"reason">>, ReasonStr},
-        {<<"ref">>, stack_hash(Stack)}
+        {<<"reason">>, ReasonStr} |
+        case Stack of [] -> []; _ -> [{<<"ref">>, stack_hash(Stack)}] end
     ]},
     send_chunk(Resp, ?l2b([$\n,?JSON_ENCODE(JsonError),$\n])),
     send_chunk(Resp, []).
@@ -890,8 +890,13 @@ maybe_decompress(Httpd, Body) ->
         throw({bad_ctype, [Else, " is not a supported content encoding."]})
     end.
 
-log_stack_trace(Stack) ->
-    couch_log:error("~p failed with trace: ~p", [stack_hash(Stack), Stack]).
+log_error_with_stack_trace({bad_request, _, _}) ->
+    ok;
+log_error_with_stack_trace({Error, Reason, Stack}) ->
+    couch_log:error("ref: ~p req_err ~p:~p ~p",
+             [stack_hash(Stack), Error, Reason, Stack]);
+log_error_with_stack_trace(_) ->
+    ok.
 
 stack_trace_id(Stack) ->
     {"X-Cloudant-Stack-Hash", stack_hash(Stack)}.


Mime
View raw message