anchor.diff:  
   -record(state, {files}).
   
  +-record(file, {
  +        name :: string(),
  +        level :: integer(),
  +        fd :: port(),
  +        inode :: integer(),
  +        flap=false :: boolean()
  +    }).
  +
  +-define(LOG(Level, Format, Args),
  +    case lager_util:level_to_num(Level) >= lager_mochiglobal:get(loglevel, 0) of
  +        true ->
  +            gen_event:notify(lager_event, {log, lager_util:level_to_num(Level),
  +                    lager_util:format_time(), [io_lib:format("[~p] ~p ", [Level, self()]), io_lib:format(Format, Args)]});
  +        _ -> ok
  +    end).
  +
  +
   init(LogFiles) ->
       Files = [begin
                   case lager_util:open_logfile(Name, true) of
                       {ok, {FD, Inode}} ->
  -                        {Name, lager_util:level_to_num(Level), FD, Inode};
  +                        #file{name=Name, level=lager_util:level_to_num(Level), fd=FD, inode=Inode};
                       Error ->
                           lager:error("Failed to open log file ~s with error ~p",
                               [Name, Error]),
  -                        undefined
  +                        #file{name=Name, level=lager_util:level_to_num(Level), flap=true}
                   end
           end ||
           {Name, Level} <- LogFiles],
  
positive.code: get_loglevel_test() ->
      {ok, Level, _} = handle_call(get_loglevel,
          #state{files=[
                  {"foo", lager_util:level_to_num(warning), 0, 0},
                  {"bar", lager_util:level_to_num(info), 0, 0}]}),
      ?assertEqual(Level, lager_util:level_to_num(info)),
      {ok, Level2, _} = handle_call(get_loglevel,
          #state{files=[
                  {"foo", lager_util:level_to_num(warning), 0, 0},
                  {"foo", lager_util:level_to_num(critical), 0, 0},
                  {"bar", lager_util:level_to_num(error), 0, 0}]}),
      ?assertEqual(Level2, lager_util:level_to_num(warning)).
  
  rotation_test() ->
      {ok, {FD, Inode}} = lager_util:open_logfile("test.log", true),
      ?assertEqual({"test.log", 0, FD, Inode},
          write({"test.log", 0, FD, Inode}, 0, "hello world")),
      file:delete("test.log"),
      Result = write({"test.log", 0, FD, Inode}, 0, "hello world"),
      %% assert file has changed
      ?assert({"test.log", 0, FD, Inode} =/= Result),
      ?assertMatch({"test.log", 0, _, _}, Result),
      file:rename("test.log", "test.log.1"),
      Result2 = write(Result, 0, "hello world"),
      %% assert file has changed
      ?assert(Result =/= Result2),
      ?assertMatch({"test.log", 0, _, _}, Result2),
      ok.
  
  -endif.
  
negative.code: 
  handle_event({log, Level, Time, Message}, #state{files=Files} = State) ->
      NewFiles = lists:map(
          fun(#file{level=L} = File) when Level >= L ->
                  write(File, Level, [Time, " ", Message, "\n"]);
              (File) ->
                  File
  