anchor.diff:      {noreply, State}.
   
   terminate(_Reason, _State) ->
  -    emqttd_ctl:unregister_cmd(trace),
       ok.
   
   code_change(_OldVsn, State, _Extra) ->
  
positive.code: -type trace_who() :: {client | topic, binary()}.
  
  -define(TRACE_OPTIONS, [{formatter_config, [time, " [",severity,"] ", message, "\n"]}]).
  
  
  %%%=============================================================================
  %%% CLI
  %%%=============================================================================
  
  cli(["list"]) ->
      lists:foreach(fun({{Who, Name}, LogFile}) -> 
              ?PRINT("trace ~s ~s -> ~s~n", [Who, Name, LogFile])
          end, all_traces());
  
  cli(["client", ClientId, "off"]) ->
      cli(trace_off, client, ClientId);
  cli(["client", ClientId, LogFile]) ->
      cli(trace_on, client, ClientId, LogFile);
  cli(["topic", Topic, "off"]) ->
      cli(trace_off, topic, Topic);
  cli(["topic", Topic, LogFile]) ->
      cli(trace_on, topic, Topic, LogFile);
  
  cli(_) ->
      ?PRINT_CMD("trace list",                       "#query all traces"),
      ?PRINT_CMD("trace client <ClientId> <LogFile>","#trace client with ClientId"),
      ?PRINT_CMD("trace client <ClientId> off",      "#stop to trace client"),
      ?PRINT_CMD("trace topic <Topic> <LogFile>",    "#trace topic with Topic"),
      ?PRINT_CMD("trace topic <Topic> off",          "#stop to trace Topic").
  
  cli(trace_on, Who, Name, LogFile) ->
      case start_trace({Who, list_to_binary(Name)}, LogFile) of
          ok ->
              ?PRINT("trace ~s ~s successfully.~n", [Who, Name]);
          {error, Error} ->
              ?PRINT("trace ~s ~s error: ~p~n", [Who, Name, Error])
      end.
  
  cli(trace_off, Who, Name) ->
      case stop_trace({Who, list_to_binary(Name)}) of
          ok -> 
              ?PRINT("stop to trace ~s ~s successfully.~n", [Who, Name]);
          {error, Error} ->
              ?PRINT("stop to trace ~s ~s error: ~p.~n", [Who, Name, Error])
      end.
  
  %%%=============================================================================
  %%% API
  
negative.code:     gen_server:call(?MODULE, all_traces).
  
  init([]) ->
      {ok, #state{level = info, trace_map = #{}}}.
  
  handle_call({start_trace, Who, LogFile}, _From, State = #state{level = Level, trace_map = TraceMap}) ->
  