Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 43619 invoked from network); 15 Jun 2010 01:38:45 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Jun 2010 01:38:45 -0000 Received: (qmail 28463 invoked by uid 500); 15 Jun 2010 01:38:45 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 28392 invoked by uid 500); 15 Jun 2010 01:38:44 -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 28384 invoked by uid 99); 15 Jun 2010 01:38:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jun 2010 01:38:44 +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, 15 Jun 2010 01:38:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 01A6323889F1; Tue, 15 Jun 2010 01:37:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r954691 - in /couchdb/branches/0.11.x/src/couchdb: couch_db.hrl couch_log.erl Date: Tue, 15 Jun 2010 01:37:54 -0000 To: commits@couchdb.apache.org From: kocolosk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100615013755.01A6323889F1@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kocolosk Date: Tue Jun 15 01:37:54 2010 New Revision: 954691 URL: http://svn.apache.org/viewvc?rev=954691&view=rev Log: backport of synchronous logging, COUCHDB-761. Patch by Randall Leeds. This patch fixes a bug where calls to get the log level could time out, resulting in an unexpected {ref(), integer()} message in the client's mailbox. This would crash some gen_servers that did not expect the message. This backport also includes r954240, the hack for logging during make check. Modified: couchdb/branches/0.11.x/src/couchdb/couch_db.hrl couchdb/branches/0.11.x/src/couchdb/couch_log.erl Modified: couchdb/branches/0.11.x/src/couchdb/couch_db.hrl URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_db.hrl?rev=954691&r1=954690&r2=954691&view=diff ============================================================================== --- couchdb/branches/0.11.x/src/couchdb/couch_db.hrl (original) +++ couchdb/branches/0.11.x/src/couchdb/couch_db.hrl Tue Jun 15 01:37:54 2010 @@ -28,18 +28,23 @@ -define(LOG_DEBUG(Format, Args), case couch_log:debug_on() of - true -> error_logger:info_report(couch_debug, {Format, Args}); + true -> + gen_event:sync_notify(error_logger, + {self(), couch_debug, {Format, Args}}); false -> ok end). -define(LOG_INFO(Format, Args), case couch_log:info_on() of - true -> error_logger:info_report(couch_info, {Format, Args}); + true -> + gen_event:sync_notify(error_logger, + {self(), couch_info, {Format, Args}}); false -> ok end). -define(LOG_ERROR(Format, Args), - error_logger:error_report(couch_error, {Format, Args})). + gen_event:sync_notify(error_logger, + {self(), couch_error, {Format, Args}})). -record(rev_info, Modified: couchdb/branches/0.11.x/src/couchdb/couch_log.erl URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_log.erl?rev=954691&r1=954690&r2=954691&view=diff ============================================================================== --- couchdb/branches/0.11.x/src/couchdb/couch_log.erl (original) +++ couchdb/branches/0.11.x/src/couchdb/couch_log.erl Tue Jun 15 01:37:54 2010 @@ -50,14 +50,23 @@ init([]) -> fun("log", "file") -> ?MODULE:stop(); ("log", "level") -> + ?MODULE:stop(); + ("log", "include_sasl") -> ?MODULE:stop() end), Filename = couch_config:get("log", "file", "couchdb.log"), - Level = couch_config:get("log", "level", "info"), + Level = level_integer(list_to_atom(couch_config:get("log", "level", "info"))), + Sasl = list_to_atom(couch_config:get("log", "include_sasl", "true")), + + case ets:info(?MODULE) of + undefined -> ets:new(?MODULE, [named_table]); + _ -> ok + end, + ets:insert(?MODULE, {level, Level}), {ok, Fd} = file:open(Filename, [append]), - {ok, {Fd, level_integer(list_to_atom(Level))}}. + {ok, {Fd, Level, Sasl}}. debug_on() -> get_level_integer() =< ?LEVEL_DEBUG. @@ -72,29 +81,35 @@ get_level() -> level_atom(get_level_integer()). get_level_integer() -> - catch gen_event:call(error_logger, couch_log, get_level_integer). + try + ets:lookup_element(?MODULE, level, 2) + catch error:badarg -> + ?LEVEL_ERROR + end. set_level_integer(Int) -> gen_event:call(error_logger, couch_log, {set_level_integer, Int}). -handle_event({error_report, _, {Pid, couch_error, {Format, Args}}}, {Fd, _LogLevel}=State) -> - log(Fd, Pid, error, Format, Args), - {ok, State}; -handle_event({error_report, _, {Pid, _, _}}=Event, {Fd, _LogLevel}=State) -> - log(Fd, Pid, error, "~p", [Event]), - {ok, State}; -handle_event({error, _, {Pid, Format, Args}}, {Fd, _LogLevel}=State) -> +handle_event({Pid, couch_error, {Format, Args}}, {Fd, _LogLevel, _Sasl}=State) -> log(Fd, Pid, error, Format, Args), {ok, State}; -handle_event({info_report, _, {Pid, couch_info, {Format, Args}}}, {Fd, LogLevel}=State) +handle_event({Pid, couch_info, {Format, Args}}, {Fd, LogLevel, _Sasl}=State) when LogLevel =< ?LEVEL_INFO -> log(Fd, Pid, info, Format, Args), {ok, State}; -handle_event({info_report, _, {Pid, couch_debug, {Format, Args}}}, {Fd, LogLevel}=State) +handle_event({Pid, couch_debug, {Format, Args}}, {Fd, LogLevel, _Sasl}=State) when LogLevel =< ?LEVEL_DEBUG -> log(Fd, Pid, debug, Format, Args), {ok, State}; -handle_event({_, _, {Pid, _, _}}=Event, {Fd, LogLevel}=State) +handle_event({error_report, _, {Pid, _, _}}=Event, {Fd, _LogLevel, Sasl}=State) +when Sasl =/= false -> + log(Fd, Pid, error, "~p", [Event]), + {ok, State}; +handle_event({error, _, {Pid, Format, Args}}, {Fd, _LogLevel, Sasl}=State) +when Sasl =/= false -> + log(Fd, Pid, error, Format, Args), + {ok, State}; +handle_event({_, _, {Pid, _, _}}=Event, {Fd, LogLevel, _Sasl}=State) when LogLevel =< ?LEVEL_TMI -> % log every remaining event if tmi! log(Fd, Pid, tmi, "~p", [Event]), @@ -102,10 +117,9 @@ when LogLevel =< ?LEVEL_TMI -> handle_event(_Event, State) -> {ok, State}. -handle_call(get_level_integer, {_Fd, LogLevel}=State) -> - {ok, LogLevel, State}; -handle_call({set_level_integer, NewLevel}, {Fd, _LogLevel}) -> - {ok, ok, {Fd, NewLevel}}. +handle_call({set_level_integer, NewLevel}, {Fd, _LogLevel, Sasl}) -> + ets:insert(?MODULE, {level, NewLevel}), + {ok, ok, {Fd, NewLevel, Sasl}}. handle_info(_Info, State) -> {ok, State}. @@ -113,7 +127,7 @@ handle_info(_Info, State) -> code_change(_OldVsn, State, _Extra) -> {ok, State}. -terminate(_Arg, {Fd, _LoggingLevel}) -> +terminate(_Arg, {Fd, _LoggingLevel, _Sasl}) -> file:close(Fd). log(Fd, Pid, Level, Format, Args) ->