Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
attempt to capture empty lines and not write them
Browse files Browse the repository at this point in the history
  • Loading branch information
voidlock committed Feb 5, 2015
1 parent cd09da3 commit 69d393c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
23 changes: 16 additions & 7 deletions src/logplex_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ handlers() ->
case {proplists:get_value(<<"tail">>, Data, tail_not_requested),
logplex_channel:lookup_flag(no_tail, ChannelId)} of
{tail_not_requested, _} ->
Resp:write_chunk(<<>>);
write_chunk(Resp, close);
{_, no_tail} ->
Resp:write_chunk(no_tail_warning()),
Resp:write_chunk(<<>>);
write_chunk(Resp, no_tail_warning()),
write_chunk(Resp, close);
_ ->
?INFO("at=tail_start channel_id=~p filters=~100p",
[ChannelId, Filters]),
Expand Down Expand Up @@ -340,7 +340,7 @@ handlers() ->

filter_and_send_chunked_logs(Resp, Logs, Filters, Num),

Resp:write_chunk(<<>>),
write_chunk(Resp, close),

{done, {200, "<chunked>"}}
end},
Expand Down Expand Up @@ -539,14 +539,23 @@ authorize(Req) ->
error_resp(RespCode, Body) ->
throw({RespCode, Body}).

write_chunk(Resp, close) ->
Resp:write_chunk(<<>>);
write_chunk(Resp, Data) ->
case iolist_size(Data) of
0 -> skip;
_ ->
Resp:write_chunk(Data)
end.

filter_and_send_chunked_logs(Resp, Logs, [], _Num) ->
[Resp:write_chunk(logplex_utils:format(logplex_utils:parse_msg(Msg))) || Msg <- lists:reverse(Logs)];
[write_chunk(Resp, logplex_utils:format(logplex_utils:parse_msg(Msg))) || Msg <- lists:reverse(Logs)];

filter_and_send_chunked_logs(Resp, Logs, Filters, Num) ->
filter_and_send_chunked_logs(Resp, Logs, Filters, Num, []).

filter_and_send_chunked_logs(Resp, Logs, _Filters, Num, Acc) when Logs == []; Num == 0 ->
Resp:write_chunk(Acc);
write_chunk(Resp, Acc);

filter_and_send_chunked_logs(Resp, [Msg|Tail], Filters, Num, Acc) ->
Msg1 = logplex_utils:parse_msg(Msg),
Expand All @@ -573,7 +582,7 @@ tail_loop(Socket, Resp, Buffer, Filters, ChannelId, BytesSent) ->
tail_filter(Filters)),
receive
{logplex_tail_data, Buffer, Data} ->
Resp:write_chunk(Data),
write_chunk(Resp, Data),
tail_loop(Socket, Resp, Buffer, Filters, ChannelId, iolist_size(Data) + BytesSent);
{tcp_data, Socket, _} ->
inet:setopts(Socket, [{active, once}]),
Expand Down
2 changes: 1 addition & 1 deletion src/logplex_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ formatted_utc_date() ->
format(#msg{ps = Ps, time = Time, source = Source, content = Content}) ->
format(Ps, Time, Source, Content);
format(_Msg) ->
"".
<<>>.

format(Ps, Time, Source, Content) ->
Ps1 =
Expand Down

0 comments on commit 69d393c

Please sign in to comment.