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:     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(
  
negative.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}.
  