anchor.diff:    erlang:send(Pid, {produce, From, Topic, Partition, Key, Value}),
     {ok, Ref}.
   
  --spec debug(pid(), list()) -> ok.
  -%% @doc Enable/disabling debugging on brod_producer and on all connections
  -%%      to brokers managed by the given brod_producer instance.
  -%%      Enable:
  -%%        brod_producer:debug(Conn, {log, print}).
  -%%        brod_producer:debug(Conn, {trace, true}).
  -%%      Disable:
  -%%        brod_producer:debug(Conn, no_debug).
  -debug(Pid, Debug) ->
  -  {ok, Sockets} = get_sockets(Pid),
  -  lists:foreach(
  -    fun(#socket{pid = SocketPid}) ->
  -        {ok, _} = gen:call(SocketPid, system, {debug, Debug})
  -    end, Sockets),
  -  {ok, _} = gen:call(Pid, system, {debug, Debug}),
  -  ok.
  +-spec debug(pid(), print | string() | none) -> ok.
  +%% @doc Enable debugging on producer and its connection to a broker
  +%%      debug(Pid, pring) prints debug info on stdout
  +%%      debug(Pid, File) prints debug info into a File
  +debug(Pid, print) ->
  +  do_debug(Pid, {trace, true}),
  +  do_debug(Pid, {log, print});
  +debug(Pid, File) when is_list(File) ->
  +  do_debug(Pid, {trace, true}),
  +  do_debug(Pid, {log_to_file, File}).
  +
  +-spec no_debug(pid()) -> ok.
  +%% @doc Disable debugging
  +no_debug(Pid) ->
  +  do_debug(Pid, no_debug).
   
   -spec get_sockets(pid()) -> {ok, [#socket{}]}.
   get_sockets(Pid) ->
  
positive.code: store_topic_buffer(Topic, LeaderBuffer, TopicBuffer) ->
    lists:keystore(Topic, 1, LeaderBuffer, {Topic, TopicBuffer}).
  
  %% Tests -----------------------------------------------------------------------
  -ifdef(TEST).
  
  
negative.code: 
  code_change(_OldVsn, State, _Extra) ->
    {ok, State}.
  
  format_status(_Opt, [_PDict, State0]) ->
    State = lists:zip(record_info(fields, state), tl(tuple_to_list(State0))),
    [{data, [{"State", State}]}].
  
  %%%_* Internal functions -------------------------------------------------------
  handle_produce(From, Topic, Partition, Key, Value, State0) ->
  