【发布时间】:2011-02-09 14:53:41
【问题描述】:
当使用rb:list() 或rb:show() 在sasl 日志中查找消息时,rb 似乎将输出转储到控制台并返回'ok';有没有办法配置 rb 让它返回实际的日志消息?
谢谢
【问题讨论】:
标签: erlang erlang-otp
当使用rb:list() 或rb:show() 在sasl 日志中查找消息时,rb 似乎将输出转储到控制台并返回'ok';有没有办法配置 rb 让它返回实际的日志消息?
谢谢
【问题讨论】:
标签: erlang erlang-otp
我一直在使用以下函数,它将日志转储到一个临时文件并读取该文件:
get_logs(LogDir) ->
TmpFile = lists:flatten(io_lib:format("log_tmp_~B_~B_~B", tuple_to_list(now()))),
try
% Make the report browser write logs to a temporary file.
% We use rb:start_link instead of rb:start, to not depend on the sasl
% application being started.
{ok, _} = rb:start_link([{start_log, TmpFile},
{report_dir, LogDir}]),
rb:show(),
% We catch errors from stopping, since we're going to get one
% if sasl isn't started. (UTSL)
catch rb:stop(),
% Ouch... let's hope the logs fit in memory.
case file:read_file(TmpFile) of
{ok, Logs} ->
Logs;
{error, Error} ->
io_lib:format("Couldn't read logs: ~p", [Error])
end
catch _:E ->
io_lib:format("Couldn't read logs: ~p", [E])
after
file:delete(TmpFile)
end.
【讨论】: