2010-04-19 46 views
0

當在sasl日誌中使用rb:list()rb:show()查找消息時,rb似乎在控制檯中轉儲輸出並返回'ok';有什麼辦法可以配置rb讓它返回實際的日誌消息嗎?Erlang rb模塊

感謝

回答

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.