X-Git-Url: https://git.xandkar.net/?p=beam_stats.git;a=blobdiff_plain;f=src%2Fbeam_stats_consumer_csv.erl;h=c9d27855de4959c54dc88fc8bf509296373c8fd5;hp=bfa61cdb34978448f96ca615618ec005c38537f6;hb=f079a56c67f6d3210dc1e4e876eab915fe299013;hpb=7264b4f392d5733d49707e58f10cf900514e2a47 diff --git a/src/beam_stats_consumer_csv.erl b/src/beam_stats_consumer_csv.erl index bfa61cd..c9d2785 100644 --- a/src/beam_stats_consumer_csv.erl +++ b/src/beam_stats_consumer_csv.erl @@ -1,6 +1,7 @@ -module(beam_stats_consumer_csv). -include("include/beam_stats.hrl"). +-include("beam_stats_logging.hrl"). -behaviour(beam_stats_consumer). @@ -56,14 +57,14 @@ terminate(#state{file=FileOpt}) -> -spec try_to_write(state(), binary()) -> state(). try_to_write(#state{file=none, path=Path}=State, _) -> - io:format("error: file closed: ~s~n", [Path]), + ?log_error("Writing to file (~p) failed: no file in state.", [Path]), State; try_to_write(#state{file={some, File}}=State, Payload) -> case file:write(File, Payload) of ok -> State ; {error, _}=Error -> - io:format("error: file:write/2 failed: ~p~n", [Error]), + ?log_error("file:write(~p, ~p) -> ~p", [File, Payload, Error]), % TODO: Maybe schedule retry? ok = file:close(File), State#state{file=none} @@ -74,11 +75,12 @@ try_to_write(#state{file={some, File}}=State, Payload) -> try_to_open_if_no_file(#state{file={some, _}}=State) -> State; try_to_open_if_no_file(#state{file=none, path=Path}=State) -> - case file:open(Path, [append]) + Options = [append], + case file:open(Path, Options) of {ok, File} -> State#state{file = {some, File}} ; {error, _}=Error -> - io:format("error: file:open/2 failed: ~p~n", [Error]), + ?log_error("file:open(~p, ~p) -> ~p", [Path, Options, Error]), State#state{file = none} end.