anchor.diff:  %%%-------------------------------------------------------------------
   %%% File    : etorrent_file_logger.erl
   %%% Author  : Jesper Louis Andersen <>
  -%%% Description : Log to a file. Loosely based on log_mf_h from the
  -%%%  erlang distribution
  +%%% Description : Log to a memory table. When entries are older than
  +%%%  12 hours, prune the entries.
   %%%
   %%% Created :  9 Jul 2008 by Jesper Louis Andersen <>
   %%%-------------------------------------------------------------------
   -module(etorrent_memory_logger).
   
   -include("log.hrl").
  +-include_lib("stdlib/include/ms_transform.hrl").
   
   -behaviour(gen_event).
   
  
positive.code: -record(state, {}).
  
  -define(TAB, ?MODULE).
  
  all_entries() ->
      ets:match_object(?TAB, '_').
  
  
negative.code:     {ok, State}.
  
  %% =======================================================================
  %% @doc Prune events which are older than a given amount of time
  %% @end
  prune_old_events() ->
      NowSecs = calendar:datetime_to_gregorian_seconds(
                          calendar:universal_time()),
      TS = NowSecs - ?OLD_PRUNE_TIME,
      PruneTime = calendar:gregorian_seconds_to_datetime(TS),
      MS = ets:fun2ms(fun({N, LT, Evt}) -> LT < PruneTime end),
      ets:select_delete(?TAB, MS),
      ok.
  