1

rb:list()使用or在 sasl 日志中查找消息时rb:show(),rb 似乎将输出转储到控制台并返回“ok”;有没有办法配置 rb 让它返回实际的日志消息?

谢谢

4

1 回答 1

0

我一直在使用以下函数,它将日志转储到一个临时文件并读取该文件:

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.
于 2010-04-21T15:38:04.370 回答