anchor.diff:  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}]}),
  +                #file{name="foo", level=lager_util:level_to_num(warning), fd=0, inode=0},
  +                #file{name="bar", level=lager_util:level_to_num(info), fd=0, inode=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}]}),
  +                #file{name="foo", level=lager_util:level_to_num(warning), fd=0, inode=0},
  +                #file{name="foo", level=lager_util:level_to_num(critical), fd=0, inode=0},
  +                #file{name="bar", level=lager_util:level_to_num(error), fd=0, inode=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")),
  +    ?assertMatch(#file{name="test.log", level=0, fd=FD, inode=Inode},
  +        write(#file{name="test.log", level=0, fd=FD, inode=Inode}, 0, "hello world")),
       file:delete("test.log"),
  -    Result = write({"test.log", 0, FD, Inode}, 0, "hello world"),
  +    Result = write(#file{name="test.log", level=0, fd=FD, inode=Inode}, 0, "hello world"),
       %% assert file has changed
  -    ?assert({"test.log", 0, FD, Inode} =/= Result),
  -    ?assertMatch({"test.log", 0, _, _}, Result),
  +    ?assert(#file{name="test.log", level=0, fd=FD, inode=Inode} =/= Result),
  +    ?assertMatch(#file{name="test.log", level=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),
  +    ?assertMatch(#file{name="test.log", level=0}, Result2),
       ok.
   
   -endif.
  
positive.code: 
  -record(state, {files}).
  
  init(LogFiles) ->
      Files = [begin
                  case lager_util:open_logfile(Name, true) of
                      {ok, {FD, Inode}} ->
                          {Name, lager_util:level_to_num(Level), FD, Inode};
                      Error ->
                          lager:error("Failed to open log file ~s with error ~p",
                              [Name, Error]),
                          undefined
                  end
          end ||
          {Name, Level} <- LogFiles],
  
negative.code: code_change(_OldVsn, State, _Extra) ->
      {ok, State}.
  
  write(#file{name=Name, fd=FD, inode=Inode, flap=Flap} = File, Level, Msg) ->
      case lager_util:ensure_logfile(Name, FD, Inode, true) of
          {ok, {NewFD, NewInode}} ->
              file:write(NewFD, Msg),
              case Level of
                  _ when Level >= 4 ->
                      %% force a sync on any message at error severity or above
                      Flap2 = case file:datasync(NewFD) of
                          {error, Reason2} when Flap == false ->
                              ?LOG(error, "Failed to write log message to file ~s: ~s", [Name, file:format_error(Reason2)]),
                              true;
                          ok ->
                              false;
                          _ ->
                              Flap
                      end,
                      File#file{fd=NewFD, inode=NewInode, flap=Flap2};
                  _ -> 
                      File#file{fd=NewFD, inode=NewInode}
              end;
          {error, Reason} ->
              case Flap of
                  true ->
                      File;
                  _ ->
                      ?LOG(error, "Failed to reopen logfile ~s with error ~w", [Name, file:format_info(Reason)]),
                      File#file{flap=true}
              end
      end.
  
  -ifdef(TEST).
  