Skip to content

Commit

Permalink
Allow POST to _log.
Browse files Browse the repository at this point in the history
POST /_log {"level":"info|debug|error", "message":"your message here"}

Patch by Robert Newson.

Closes COUCHDB-464
  • Loading branch information
janl committed Oct 30, 2011
1 parent f94530d commit 6cffccd
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/couchdb/couch_httpd_misc_handlers.erl
Expand Up @@ -254,7 +254,22 @@ handle_log_req(#httpd{method='GET'}=Req) ->
]),
send_chunk(Resp, Chunk),
last_chunk(Resp);
handle_log_req(#httpd{method='POST'}=Req) ->
{PostBody} = couch_httpd:json_body_obj(Req),
Level = couch_util:get_value(<<"level">>, PostBody),
Message = ?b2l(couch_util:get_value(<<"message">>, PostBody)),
case Level of
<<"debug">> ->
?LOG_DEBUG(Message, []),
send_json(Req, 200, {[{ok, true}]});
<<"info">> ->
?LOG_INFO(Message, []),
send_json(Req, 200, {[{ok, true}]});
<<"error">> ->
?LOG_ERROR(Message, []),
send_json(Req, 200, {[{ok, true}]});
_ ->
send_json(Req, 400, {[{error, ?l2b(io_lib:format("Unrecognized log level '~s'", [Level]))}]})
end;
handle_log_req(Req) ->
send_method_not_allowed(Req, "GET").


send_method_not_allowed(Req, "GET,POST").

0 comments on commit 6cffccd

Please sign in to comment.