From commits-return-2453-apmail-couchdb-commits-archive=couchdb.apache.org@couchdb.apache.org Tue May 12 22:45:52 2009 Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 77818 invoked from network); 12 May 2009 22:45:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 12 May 2009 22:45:49 -0000 Received: (qmail 53809 invoked by uid 500); 12 May 2009 22:45:45 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 52219 invoked by uid 500); 12 May 2009 22:45:41 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 51601 invoked by uid 99); 12 May 2009 22:45:36 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 May 2009 22:45:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 May 2009 22:45:23 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0DE3A23888E3; Tue, 12 May 2009 19:36:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r774045 - in /couchdb/trunk: etc/couchdb/default.ini.tpl.in src/couchdb/couch_httpd_misc_handlers.erl src/couchdb/couch_log.erl src/couchdb/couch_util.erl Date: Tue, 12 May 2009 19:36:15 -0000 To: commits@couchdb.apache.org From: jan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090512193616.0DE3A23888E3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jan Date: Tue May 12 19:36:15 2009 New Revision: 774045 URL: http://svn.apache.org/viewvc?rev=774045&view=rev Log: Add non-streaming log-file handler. A GET request to /_log will show the last 1000 bytes of the logflie. More bytes can be requested with GET /_log?bytes=10000. Modified: couchdb/trunk/etc/couchdb/default.ini.tpl.in couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl couchdb/trunk/src/couchdb/couch_log.erl couchdb/trunk/src/couchdb/couch_util.erl Modified: couchdb/trunk/etc/couchdb/default.ini.tpl.in URL: http://svn.apache.org/viewvc/couchdb/trunk/etc/couchdb/default.ini.tpl.in?rev=774045&r1=774044&r2=774045&view=diff ============================================================================== --- couchdb/trunk/etc/couchdb/default.ini.tpl.in (original) +++ couchdb/trunk/etc/couchdb/default.ini.tpl.in Tue May 12 19:36:15 2009 @@ -59,6 +59,7 @@ _uuids = {couch_httpd_misc_handlers, handle_uuids_req} _restart = {couch_httpd_misc_handlers, handle_restart_req} _stats = {couch_httpd_stats_handlers, handle_stats_req} +_log = {couch_httpd_misc_handlers, handle_log_req} [httpd_db_handlers] _compact = {couch_httpd_db, handle_compact_req} Modified: couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl?rev=774045&r1=774044&r2=774045&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl (original) +++ couchdb/trunk/src/couchdb/couch_httpd_misc_handlers.erl Tue May 12 19:36:15 2009 @@ -14,7 +14,7 @@ -export([handle_welcome_req/2,handle_favicon_req/2,handle_utils_dir_req/2, handle_all_dbs_req/1,handle_replicate_req/1,handle_restart_req/1, - handle_uuids_req/1,handle_config_req/1, + handle_uuids_req/1,handle_config_req/1,handle_log_req/1, handle_task_status_req/1]). -export([increment_update_seq_req/2]). @@ -195,3 +195,15 @@ increment_update_seq_req(Req, _Db) -> send_method_not_allowed(Req, "POST"). +% httpd log handlers + +handle_log_req(#httpd{method='GET'}=Req) -> + LastBytes = list_to_integer(couch_httpd:qs_value(Req, "bytes", "1000")), + {ok, Resp} = start_chunked_response(Req, 200, [ + % send a plaintext response + {"Content-Type", "text/plain; charset=utf-8"} + ]), + send_chunk(Resp, couch_log:read(LastBytes)), + send_chunk(Resp, ""); +handle_log_req(Req) -> + send_method_not_allowed(Req, "GET"). Modified: couchdb/trunk/src/couchdb/couch_log.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_log.erl?rev=774045&r1=774044&r2=774045&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/couch_log.erl (original) +++ couchdb/trunk/src/couchdb/couch_log.erl Tue May 12 19:36:15 2009 @@ -16,6 +16,7 @@ -export([start_link/0,stop/0]). -export([debug_on/0,info_on/0,get_level/0,get_level_integer/0, set_level/1]). -export([init/1, handle_event/2, terminate/2, code_change/3, handle_info/2, handle_call/2]). +-export([read/1]). -define(LEVEL_ERROR, 3). -define(LEVEL_INFO, 2). @@ -120,3 +121,16 @@ ok = io:format("[~s] [~p] ~s~n", [Level, Pid, Msg]), % dump to console too {ok, Msg2, _} = regexp:gsub(lists:flatten(Msg),"\\r\\n|\\r|\\n", "\r\n"), ok = io:format(Fd, "[~s] [~s] [~p] ~s\r~n\r~n", [httpd_util:rfc1123_date(), Level, Pid, Msg2]). + +read(LastBytes) -> + LogFileName = couch_config:get("log", "file"), + LogFileSize = couch_util:file_read_size(LogFileName), + + {ok, Fd} = file:open(LogFileName, [binary]), + Start = lists:max([LogFileSize - LastBytes, 0]), + + % TODO: truncate chopped first line + % TODO: make streaming + + {ok, Chunk} = file:pread(Fd, Start, LogFileSize), + Chunk. Modified: couchdb/trunk/src/couchdb/couch_util.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_util.erl?rev=774045&r1=774044&r2=774045&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/couch_util.erl (original) +++ couchdb/trunk/src/couchdb/couch_util.erl Tue May 12 19:36:15 2009 @@ -17,8 +17,10 @@ -export([new_uuid/0, rand32/0, implode/2, collate/2, collate/3]). -export([abs_pathname/1,abs_pathname/2, trim/1, ascii_lower/1]). -export([encodeBase64/1, decodeBase64/1, to_hex/1,parse_term/1,dict_find/3]). +-export([file_read_size/1]). -include("couch_db.hrl"). +-include_lib("kernel/include/file.hrl"). % arbitrarily chosen amount of memory to use before flushing to disk -define(FLUSH_MAX_MEM, 10000000). @@ -291,3 +293,11 @@ error -> DefaultValue end. + + +file_read_size(FileName) -> + case file:read_file_info(FileName) of + {ok, FileInfo} -> + FileInfo#file_info.size; + Error -> Error + end.