couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r1067877 - in /couchdb/branches/1.1.x/src/couchdb: couch_db.hrl couch_log.erl
Date Mon, 07 Feb 2011 08:27:30 GMT
Author: fdmanana
Date: Mon Feb  7 08:27:30 2011
New Revision: 1067877

URL: http://svn.apache.org/viewvc?rev=1067877&view=rev
Log:
Merged revision 1067873 from trunk

More efficient logging, closes COUCHDB-1054

Modified:
    couchdb/branches/1.1.x/src/couchdb/couch_db.hrl
    couchdb/branches/1.1.x/src/couchdb/couch_log.erl

Modified: couchdb/branches/1.1.x/src/couchdb/couch_db.hrl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_db.hrl?rev=1067877&r1=1067876&r2=1067877&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_db.hrl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_db.hrl Mon Feb  7 08:27:30 2011
@@ -25,26 +25,9 @@
 
 -define(DEFAULT_ATTACHMENT_CONTENT_TYPE, <<"application/octet-stream">>).
 
--define(LOG_DEBUG(Format, Args),
-    case couch_log:debug_on() of
-        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 ->
-            gen_event:sync_notify(error_logger,
-                {self(), couch_info, {Format, Args}});
-        false -> ok
-    end).
-
--define(LOG_ERROR(Format, Args),
-    gen_event:sync_notify(error_logger,
-            {self(), couch_error, {Format, Args}})).
-
+-define(LOG_DEBUG(Format, Args), couch_log:debug(Format, Args)).
+-define(LOG_INFO(Format, Args), couch_log:info(Format, Args)).
+-define(LOG_ERROR(Format, Args), couch_log:error(Format, Args)).
 
 -record(rev_info,
     {

Modified: couchdb/branches/1.1.x/src/couchdb/couch_log.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_log.erl?rev=1067877&r1=1067876&r2=1067877&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_log.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_log.erl Mon Feb  7 08:27:30 2011
@@ -14,6 +14,7 @@
 -behaviour(gen_event).
 
 -export([start_link/0,stop/0]).
+-export([debug/2, info/2, error/2]).
 -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/2]).
@@ -23,6 +24,29 @@
 -define(LEVEL_DEBUG, 1).
 -define(LEVEL_TMI, 0).
 
+debug(Format, Args) ->
+    case debug_on() of
+    false ->
+        ok;
+    true ->
+        {ConsoleMsg, FileMsg} = get_log_messages(self(), debug, Format, Args),
+        gen_event:sync_notify(error_logger, {couch_debug, ConsoleMsg, FileMsg})
+    end.
+
+info(Format, Args) ->
+    case info_on() of
+    false ->
+        ok;
+    true ->
+        {ConsoleMsg, FileMsg} = get_log_messages(self(), info, Format, Args),
+        gen_event:sync_notify(error_logger, {couch_info, ConsoleMsg, FileMsg})
+    end.
+
+error(Format, Args) ->
+    {ConsoleMsg, FileMsg} = get_log_messages(self(), error, Format, Args),
+    gen_event:sync_notify(error_logger, {couch_error, ConsoleMsg, FileMsg}).
+
+
 level_integer(error)    -> ?LEVEL_ERROR;
 level_integer(info)     -> ?LEVEL_INFO;
 level_integer(debug)    -> ?LEVEL_DEBUG;
@@ -96,24 +120,26 @@ get_level_integer() ->
 set_level_integer(Int) ->
     gen_event:call(error_logger, couch_log, {set_level_integer, Int}).
 
-handle_event({Pid, couch_error, {Format, Args}}, {Fd, _LogLevel, _Sasl}=State) ->
-    log(Fd, Pid, error, Format, Args),
+handle_event({couch_error, ConMsg, FileMsg}, {Fd, _LogLevel, _Sasl}=State) ->
+    log(Fd, ConMsg, FileMsg),
     {ok, State};
-handle_event({Pid, couch_info, {Format, Args}}, {Fd, LogLevel, _Sasl}=State)
+handle_event({couch_info, ConMsg, FileMsg}, {Fd, LogLevel, _Sasl}=State)
 when LogLevel =< ?LEVEL_INFO ->
-    log(Fd, Pid, info, Format, Args),
+    log(Fd, ConMsg, FileMsg),
     {ok, State};
-handle_event({Pid, couch_debug, {Format, Args}}, {Fd, LogLevel, _Sasl}=State)
+handle_event({couch_debug, ConMsg, FileMsg}, {Fd, LogLevel, _Sasl}=State)
 when LogLevel =< ?LEVEL_DEBUG ->
-    log(Fd, Pid, debug, Format, Args),
+    log(Fd, ConMsg, FileMsg),
     {ok, State};
 handle_event({error_report, _, {Pid, _, _}}=Event, {Fd, _LogLevel, Sasl}=State)
 when Sasl =/= false ->
-    log(Fd, Pid, error, "~p", [Event]),
+    {ConMsg, FileMsg} = get_log_messages(Pid, error, "~p", [Event]),
+    log(Fd, ConMsg, FileMsg),
     {ok, State};
 handle_event({error, _, {Pid, Format, Args}}, {Fd, _LogLevel, Sasl}=State)
 when Sasl =/= false ->
-    log(Fd, Pid, error, Format, Args),
+    {ConMsg, FileMsg} = get_log_messages(Pid, error, Format, Args),
+    log(Fd, ConMsg, FileMsg),
     {ok, State};
 handle_event({_, _, {Pid, _, _}}=Event, {Fd, LogLevel, _Sasl}=State)
 when LogLevel =< ?LEVEL_TMI ->
@@ -143,6 +169,16 @@ log(Fd, Pid, Level, Format, Args) ->
         [global, {return, list}]),
     ok = io:format(Fd, "[~s] [~s] [~p] ~s\r~n", [httpd_util:rfc1123_date(), Level, Pid, Msg2]).
 
+log(Fd, ConsoleMsg, FileMsg) ->
+    ok = io:put_chars(ConsoleMsg),
+    ok = io:put_chars(Fd, FileMsg).
+
+get_log_messages(Pid, Level, Format, Args) ->
+    ConsoleMsg = io_lib:format(
+        "[~s] [~p] " ++ Format ++ "~n", [Level, Pid | Args]),
+    FileMsg = ["[", httpd_util:rfc1123_date(), "] ", ConsoleMsg],
+    {iolist_to_binary(ConsoleMsg), iolist_to_binary(FileMsg)}.
+
 read(Bytes, Offset) ->
     LogFileName = couch_config:get("log", "file"),
     LogFileSize = filelib:file_size(LogFileName),



Mime
View raw message