anchor.diff:  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),
  -    {ok, State};
  -handle_event({couch_info, ConMsg}, #state{level = LogLevel} = State)
  +handle_event({couch_error, ConMsg, FileMsg}, State) ->
  +    log(State, ConMsg, FileMsg),
  +    {ok, State};
  +handle_event({couch_info, ConMsg, FileMsg}, #state{level = LogLevel} = State)
   when LogLevel =< ?LEVEL_INFO ->
  -    ok = io:put_chars(ConMsg),
  -    {ok, State};
  -handle_event({couch_debug, ConMsg}, #state{level = LogLevel} = State)
  +    log(State, ConMsg, FileMsg),
  +    {ok, 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}.
  
positive.code: -define(LEVEL_INFO, 2).
  -define(LEVEL_DEBUG, 1).
  
  -define(DISK_LOGGER, couch_disk_logger).
  
  -record(state, {
      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}).
  
  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}).
  
  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}).
  
  
  level_integer(error)    -> ?LEVEL_ERROR;
  
negative.code:     ets:insert(?MODULE, {level, NewLevel}),
      {ok, ok, State#state{level = NewLevel}}.
  
  handle_info(_Info, State) ->
      {ok, State}.
  
  code_change(_OldVsn, State, _Extra) ->
      {ok, State}.
  
  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(
  