* 使用lager的trace功能,可以从任何节点发起trace, 相关节点收到trace命令后,开始收集符合trace条件的日志信息
* trace到的日志信息都汇集到lager_amqp_backend中
h2. 方案
* lager_amqp_backend增加 amqp_tracer.erl 模块
* amqp_tracer:trace_amqp
* amqp_tracer:stop_trace
* amqp_tracer: clear_all_traces
h2. 设计
h2. 配置
* app.last.config:在lager的handler配置项下增加
<pre>
{lager_amqp_backend, [
{name, "lager_amqp_backend"},
{level, info},
{exchange, <<"lager_amqp_backend">>},
{amqp_user, <<"guest">>},
{amqp_pass, <<"guest">>},
{amqp_vhost, <<"/">>},
{amqp_host, "rabbitmq.lk.com"},
{routing_key, <<"amqp_backend">>},
{amqp_port, 5672}
]}
</pre>
h2. 操作
* 设置trace
<pre>
amqp_tracer:start_link().
amqp_tracer:trace_amqp(<<"amqp_test">>, [{request, 100}], debug).
</pre>
* 订阅amqp消息
<pre>
amqp_subscriber:start_link(<<"amqp_test">>).
</pre>
h2. 测试
amqp_test.erl
<pre>
-module(amqp_client).
-export([test/0]).
test() ->
lager:debug([{request, 100}], "Lager debug"),
lager:info([{request, 100}], "Lager info"),
lager:error([{request, 100}], "Lager error").
</pre>