couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [1/2] git commit: COUCHDB-1380 Revert "Better logger performance"
Date Tue, 17 Jan 2012 14:46:39 GMT
Updated Branches:
  refs/heads/1.2.x 8d83b39a0 -> 3b63f8daf
  refs/heads/master ef368d7c0 -> 6228b1785


COUCHDB-1380 Revert "Better logger performance"

This reverts commit 9f2398faef3936a844caffbaf3eef8675383ccfd which
switched couch_log to use disk_log. Unfortunately that module performs
positioned writes which prevents the usual logrotation strategy from
working correctly.


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

Branch: refs/heads/master
Commit: 6228b178543429732c17b3a784c957d3782573b9
Parents: ef368d7
Author: Robert Newson <rnewson@apache.org>
Authored: Tue Jan 17 14:26:01 2012 +0000
Committer: Robert Newson <rnewson@apache.org>
Committed: Tue Jan 17 14:46:23 2012 +0000

----------------------------------------------------------------------
 src/couchdb/couch_log.erl        |   56 +++++++++++++-------------------
 test/etap/172-os-daemon-errors.t |    1 -
 2 files changed, 23 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb/blob/6228b178/src/couchdb/couch_log.erl
----------------------------------------------------------------------
diff --git a/src/couchdb/couch_log.erl b/src/couchdb/couch_log.erl
index 1b05f4d..8e24cab 100644
--- a/src/couchdb/couch_log.erl
+++ b/src/couchdb/couch_log.erl
@@ -27,29 +27,23 @@
 -define(LEVEL_INFO, 2).
 -define(LEVEL_DEBUG, 1).
 
--define(DISK_LOGGER, couch_disk_logger).
-
 -record(state, {
+    fd,
     level,
     sasl
 }).
 
 debug(Format, Args) ->
     {ConsoleMsg, FileMsg} = get_log_messages(self(), debug, Format, Args),
-    ok = disk_log:balog(?DISK_LOGGER, FileMsg),
-    gen_event:sync_notify(error_logger, {couch_debug, ConsoleMsg}).
+    gen_event:sync_notify(error_logger, {couch_debug, ConsoleMsg, FileMsg}).
 
 info(Format, Args) ->
     {ConsoleMsg, FileMsg} = get_log_messages(self(), info, Format, Args),
-    ok = disk_log:balog(?DISK_LOGGER, FileMsg),
-    gen_event:sync_notify(error_logger, {couch_info, ConsoleMsg}).
+    gen_event:sync_notify(error_logger, {couch_info, ConsoleMsg, FileMsg}).
 
 error(Format, Args) ->
     {ConsoleMsg, FileMsg} = get_log_messages(self(), error, Format, Args),
-    % Synchronous logging for error messages only. We want to reduce the
-    % chances of missing any if server is killed.
-    ok = disk_log:blog(?DISK_LOGGER, FileMsg),
-    gen_event:sync_notify(error_logger, {couch_error, ConsoleMsg}).
+    gen_event:sync_notify(error_logger, {couch_error, ConsoleMsg, FileMsg}).
 
 
 level_integer(error)    -> ?LEVEL_ERROR;
@@ -92,13 +86,11 @@ init([]) ->
     end,
     ets:insert(?MODULE, {level, Level}),
 
-    DiskLogOptions = [
-        {file, Filename}, {name, ?DISK_LOGGER},
-        {format, external}, {type, halt}, {notify, true}
-    ],
-    case disk_log:open(DiskLogOptions) of
-    {ok, ?DISK_LOGGER} ->
-        {ok, #state{level = Level, sasl = Sasl}};
+    case file:open(Filename, [append]) of
+    {ok, Fd} ->
+        {ok, #state{fd = Fd, level = Level, sasl = Sasl}};
+    {error, eacces} ->
+        {stop, {file_permission_error, Filename}};
     Error ->
         {stop, Error}
     end.
@@ -125,26 +117,24 @@ get_level_integer() ->
 set_level_integer(Int) ->
     gen_event:call(error_logger, couch_log, {set_level_integer, Int}).
 
-handle_event({couch_error, ConMsg}, State) ->
-    ok = io:put_chars(ConMsg),
+handle_event({couch_error, ConMsg, FileMsg}, State) ->
+    log(State, ConMsg, FileMsg),
     {ok, State};
-handle_event({couch_info, ConMsg}, #state{level = LogLevel} = State)
+handle_event({couch_info, ConMsg, FileMsg}, #state{level = LogLevel} = State)
 when LogLevel =< ?LEVEL_INFO ->
-    ok = io:put_chars(ConMsg),
+    log(State, ConMsg, FileMsg),
     {ok, State};
-handle_event({couch_debug, ConMsg}, #state{level = LogLevel} = State)
+handle_event({couch_debug, ConMsg, FileMsg}, #state{level = LogLevel} = State)
 when LogLevel =< ?LEVEL_DEBUG ->
-    ok = io:put_chars(ConMsg),
+    log(State, ConMsg, FileMsg),
     {ok, State};
 handle_event({error_report, _, {Pid, _, _}}=Event, #state{sasl = true} = St) ->
     {ConMsg, FileMsg} = get_log_messages(Pid, error, "~p", [Event]),
-    ok = disk_log:blog(?DISK_LOGGER, FileMsg),
-    ok = io:put_chars(ConMsg),
+    log(St, ConMsg, FileMsg),
     {ok, St};
 handle_event({error, _, {Pid, Format, Args}}, #state{sasl = true} = State) ->
     {ConMsg, FileMsg} = get_log_messages(Pid, error, Format, Args),
-    ok = disk_log:blog(?DISK_LOGGER, FileMsg),
-    ok = io:put_chars(ConMsg),
+    log(State, ConMsg, FileMsg),
     {ok, State};
 handle_event(_Event, State) ->
     {ok, State}.
@@ -153,18 +143,18 @@ handle_call({set_level_integer, NewLevel}, State) ->
     ets:insert(?MODULE, {level, NewLevel}),
     {ok, ok, State#state{level = NewLevel}}.
 
-handle_info({disk_log, _Node, _Log, {error_status, Status}}, _State) ->
-    io:format("Disk logger error: ~p~n", [Status]),
-    % couch_event_sup will restart us.
-    remove_handler;
 handle_info(_Info, State) ->
     {ok, State}.
 
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
 
-terminate(_Arg, _State) ->
-    ok = disk_log:close(?DISK_LOGGER).
+terminate(_Arg, #state{fd = Fd}) ->
+    file:close(Fd).
+
+log(#state{fd = Fd}, ConsoleMsg, FileMsg) ->
+    ok = io:put_chars(ConsoleMsg),
+    ok = io:put_chars(Fd, FileMsg).
 
 get_log_messages(Pid, Level, Format, Args) ->
     ConsoleMsg = unicode:characters_to_binary(io_lib:format(

http://git-wip-us.apache.org/repos/asf/couchdb/blob/6228b178/test/etap/172-os-daemon-errors.t
----------------------------------------------------------------------
diff --git a/test/etap/172-os-daemon-errors.t b/test/etap/172-os-daemon-errors.t
index 39bdfee..bde5c6f 100755
--- a/test/etap/172-os-daemon-errors.t
+++ b/test/etap/172-os-daemon-errors.t
@@ -56,7 +56,6 @@ main(_) ->
 
 test() ->
     couch_config:start_link(config_files()),
-    couch_log:start_link(),
     couch_os_daemons:start_link(),
 
     etap:diag("Daemon not executable."),


Mime
View raw message