Erlang rb 模块

发布于 2024-08-29 12:50:26 字数 107 浏览 3 评论 0原文

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

谢谢

When looking up messages in a sasl log using rb:list() or rb:show(), rb seems to dump the output in the console and return 'ok'; is there any way to configure rb to get it to return the actual log message ?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很糊涂小朋友 2024-09-05 12:50:26

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

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.

I've been using the following function, which dumps the logs to a temporary file and reads that file:

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文