anchor.diff:      end,
       ets:insert(?MODULE, {level, Level}),
   
  -    case file:open(Filename, [append]) of
  -    {ok, Fd} ->
  -        {ok, #state{fd = Fd, level = Level, sasl = Sasl}};
  -    {error, eacces} ->
  -        {stop, {file_permission_error, Filename}};
  +    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}};
       Error ->
           {stop, Error}
       end.
  
positive.code: set_level_integer(Int) ->
      gen_event:call(error_logger, couch_log, {set_level_integer, Int}).
  
  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 ->
      log(State, ConMsg, FileMsg),
      {ok, State};
  handle_event({couch_debug, ConMsg, FileMsg}, #state{level = LogLevel} = State)
  when LogLevel =< ?LEVEL_DEBUG ->
      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]),
      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),
      log(State, ConMsg, FileMsg),
      {ok, State};
  handle_event(_Event, State) ->
      {ok, State}.
  
negative.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;
  