trace 命令

trace 命令用于追踪某个客户端或 Topic,打印日志信息到文件。

trace list查询全部开启的追踪
trace start client <ClientId> <File> [<Level>]开启 Client 追踪,存储指定等级的日志到文件
trace stop client <ClientId>关闭 Client 追踪
trace start topic <Topic> <File> [<Level>]开启 Topic 追踪,存储指定等级的日志到文件
trace stop topic <Topic>关闭 Topic 追踪

Tip

使用 trace 之前,需要将主日志等级(primary logger level) 设置成足够低的值。为提高系统运行性能,默认的主日志等级是 error。

trace start client <ClientId> <File> [<Level>]

开启 Client 追踪:

  1. $ ./bin/emqx_ctl log primary-level debug
  2. debug
  3. $ ./bin/emqx_ctl trace start client clientid log/clientid_trace.log
  4. trace client clientid successfully
  5. $ ./bin/emqx_ctl trace start client clientid2 log/clientid2_trace.log error
  6. trace client_id clientid2 successfully

trace stop client <ClientId>

关闭 Client 追踪:

  1. $ ./bin/emqx_ctl trace stop client clientid
  2. stop tracing client_id clientid successfully

trace start topic <Topic> <File> [<Level>]

开启 Topic 追踪:

  1. $ ./bin/emqx_ctl log primary-level debug
  2. debug
  3. $ ./bin/emqx_ctl trace start topic topic log/topic_trace.log
  4. trace topic topic successfully
  5. $ ./bin/emqx_ctl trace start topic topic2 log/topic2_trace.log error
  6. trace topic topic2 successfully

trace stop topic <Topic>

关闭 Topic 追踪:

  1. $ ./bin/emqx_ctl trace topic topic off
  2. stop tracing topic topic successfully

trace list

查询全部开启的追踪:

  1. $ ./bin/emqx_ctl trace list
  2. Trace(client_id=clientid2, level=error, destination="log/clientid2_trace.log")
  3. Trace(topic=topic2, level=error, destination="log/topic2_trace.log")