anchor.diff:      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(
  
positive.code: 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)
  when LogLevel =< ?LEVEL_INFO ->
      ok = io:put_chars(ConMsg),
      {ok, State};
  handle_event({couch_debug, ConMsg}, #state{level = LogLevel} = State)
  when LogLevel =< ?LEVEL_DEBUG ->
      ok = io:put_chars(ConMsg),
      {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),
      {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),
      {ok, State};
  handle_event(_Event, State) ->
      {ok, State}.
  
negative.code: -define(LEVEL_INFO, 2).
  -define(LEVEL_DEBUG, 1).
  
  -record(state, {
      fd,
      level,
      sasl
  }).
  
  debug(Format, Args) ->
      {ConsoleMsg, FileMsg} = get_log_messages(self(), debug, Format, Args),
      gen_event:sync_notify(error_logger, {couch_debug, ConsoleMsg, FileMsg}).
  
  info(Format, Args) ->
      {ConsoleMsg, FileMsg} = get_log_messages(self(), info, Format, Args),
      gen_event:sync_notify(error_logger, {couch_info, ConsoleMsg, FileMsg}).
  
  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;
  