anchor.diff:              io_lib:format(Text, Data)
       end.
   
  +
   do_log(_Output, {at_once, _Fun}, ToLog, Buffer) ->
       [ToLog | Buffer];
   do_log(_Output, delayed, ToLog, Buffer) when length(Buffer) < ?BUFFER_SIZE_N ->
  
positive.code:     timer:send_interval(?MEM_SOFTL_CHKINTERVAL, check_softlimit),
      timer:send_interval(?MEM_HARDL_CHKINTERVAL, check_hardlimit),
  
      {ok, #state{loglevel=LogLevel, log_timestamp=LogTimestamp,
                  format=Format, eagerness=Eagerness, output=Output2}}.
  
  terminate(_Reason, _State) ->
      ok.
  
  handle_call({stop, PolicyFunParam}, _From, State=#state{output=Output, 
                                                          eagerness=Eagerness, 
                                                          buffer=Buffer}) ->
      WhatToDo = case Eagerness of
                     {at_once, PolicyFun} ->
                         PolicyFun(PolicyFunParam);
                     _ -> flush
                 end,
      case  WhatToDo of
          flush ->
              Output2 = open(Output),                      
              flush(Output2, Buffer),
              close(Output2);
          drop ->
              drop
      end,    
      {stop, normal, ok, State};
  handle_call(flush_and_stop, _From, State=#state{output=Output, buffer=Buffer}) ->
      Output2 = open(Output),
      flush(Output2, Buffer),
      close(Output2),
      {stop, normal, ok, State};
  handle_call(drop_and_stop, _From, State=#state{output=Output}) ->
      close(Output),
  
negative.code:         Mem >= ?MEM_HARDLIMIT -> %% very unlikely...
              close(Output),
              {stop, mem_hardlimit_exceeded, State}
      end;
  %% TODO: check CPU/IO/etc usage
  
  % Webmachine left without saying goodbye.
  handle_info({'DOWN', Ref, process, _Pid, Reason}, State = #state{wm_mref=Ref}) ->
      State2 = do_handle_log("Unexpected Webmachine DOWN: ~p~n", [Reason], State),
      do_handle_flush(State2),
      {stop, normal, State2}.
  
  code_change(_OldVsn, State, _Extra) -> {ok, State}.
  
  %% 
  %% Internal functions
  %%
  
  do_handle_log(Text, Data, 
              State=#state{output=Output,
                           log_timestamp=LogTimestamp,
                           format=Format, 
                           eagerness=Eagerness, 
                           buffer=Buffer}) ->   
      ToLog = fmt_log(Format, LogTimestamp, {Text, Data}),
      Buffer2 = do_log(Output, Eagerness, ToLog, Buffer),
      State#state{buffer=Buffer2}.
  
  do_handle_flush(#state{output=Output, buffer=Buffer}) ->
      Output2 = open(Output),
      flush(Output2, Buffer),
      close(Output2).
  
  
  
  fmt_timestamp(text) ->
      {{Y, M, D}, {H, Mm, S}} = calendar:local_time(),
  