anchor.diff:  %%%===================================================================
   state_from_params(OrigState = #state{level = OldLevel,
                                        table = OldTable,
  +                                     application = OldApplication,
                                        tn_event = OldTableEvent}, Params) ->
       Level = proplists:get_value(level, Params, OldLevel),
       Table = proplists:get_value(table, Params, OldTable),
       TableEvent = proplists:get_value(tn_event, Params, OldTableEvent),
  +    Application = proplists:get_value(application, Params, OldApplication),
  +    Modules = case application:get_key(Application, modules) of
  +                  undefined -> OrigState#state.modules;
  +                  {ok, Mods} -> Mods
  +              end,
  +    OrigState#state{level=lager_util:level_to_num(Level),
  +                    table=Table, tn_event = TableEvent,
  +                    application = Application,
  +                    modules = Modules}.
   
  -    OrigState#state{level=lager_util:level_to_num(Level),
  -                    table=Table,
  -                    tn_event = TableEvent}.
  -
  -%%%===================================================================
  -%%% Tests
  -%%%===================================================================
  -
  -test() ->
  -    application:load(lager),
  -    application:set_env(lager, handlers, [{lager_console_backend, debug},
  -                                          {?MODULE, [{level, info},
  -                                                     {table, 'ddLog@'},
  -                                                    ]},
  -                                          {lager_file_backend,
  -                                           [{"error.log", error, 10485760, "$D0", 5},
  -                                            {"console.log", info, 10485760, "$D0", 5}]}]),
  -    application:set_env(lager, error_logger_redirect, false),
  -    lager:start(),
  -    lager:info("Test INFO message"),
  -    lager:debug("Test DEBUG message"),
  -    lager:error("Test ERROR message"),
  -    lager:info([{imem_table, customers}, {key, 123456}, {client_id, "abc"}], "TEST debug message"),
  -    lager:warning([{a,b}, {c,d}], "Hello", []),
  -    lager:info("Info ~p", ["variable"]).
  +% test() ->
  +%     application:load(lager),
  +%     application:set_env(lager, handlers, [{lager_console_backend, debug},
  +%                                           {?MODULE, [{level, info},
  +%                                                      {table, 'ddLog@'}
  +%                                                     ]},
  +%                                           {lager_file_backend,
  +%                                            [{"error.log", error, 10485760, "$D0", 5},
  +%                                             {"console.log", info, 10485760, "$D0", 5}]}]),
  +%     application:set_env(lager, error_logger_redirect, false),
  +%     lager:start(),
  +%     lager:info("Test INFO message"),
  +%     lager:debug("Test DEBUG message"),
  +%     lager:error("Test ERROR message"),
  +%     lager:info([{imem_table, customers}, {key, 123456}, {client_id, "abc"}], "TEST debug message"),
  +%     lager:warning([{a,b}, {c,d}], "Hello", []),
  +%     lager:info("Info ~p", ["variable"]).
  
positive.code:             Message = lager_msg:message(LagerMsg),
              Metadata = lager_msg:metadata(LagerMsg),
              Mod = proplists:get_value(module, Metadata),
              Fun = proplists:get_value(function, Metadata),
              Line = proplists:get_value(line, Metadata),
  
              Pid = proplists:get_value(pid, Metadata),
              Fields = [P || {K,_} = P <- Metadata, K /= node , K /= application, K /= module,
                             K /= function, K /= line, K /= pid, K /= imem_table],
  
              LogTable = proplists:get_value(imem_table, Metadata, DefaultTable),
              LogRecord =
              case LogTable == DefaultTable of
                  true ->
                      ddLog;
                  false ->
                      %% LogTable == LogRecord
                      LogTable
              end,
  
              NPid = case is_list(Pid) of
                  true ->
                      list_to_pid(Pid);
                  false ->
                      Pid
              end,
  
              EntryTuple = list_to_tuple([LogRecord,
                                          Date,
                                          lager_util:num_to_level(Level),
                                          NPid,
                                          Mod,
                                          Fun,
                                          Line,
                                          node(),
                                          Fields,
                                          list_to_binary(Message),
                                          [] %  Stacktrace
                                         ]),
              try
                  imem_meta:dirty_write(LogTable, EntryTuple)
              catch
                  _:Error ->
                      io:format(user, "[~p:~p] failed to write to ~p, ~p~n",
                                [?MODULE, ?LINE, LogTable, Error])
              end;
          false ->
              ok
      end,
      {ok, State};
  handle_event({lager_imem_options, Params}, State) ->
      {ok, state_from_params(State, Params)};
  
  
negative.code:          terminate/2,
           code_change/3]).
  -export([trace/1, trace/2]).
  %% -export([test/0]).
  
  -record(state, {
          tn_event,
          level = info,
          application,
          modules = [],
          table}).
  
  %%%===================================================================
  %%% trace
  