Skip to content

Commit

Permalink
Add limit parameter.
Browse files Browse the repository at this point in the history
  • Loading branch information
vjache committed May 8, 2012
1 parent ffe853b commit ba8f7f3
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/error_log_tool.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%% -*- mode: erlang; -*-
{application, error_log_tool,
[{description, "An Error Log Tool"},
{vsn, "0.0.2"},
{vsn, "0.1.0"},
{registered, []},
{build_dependencies, []},
{env, []},
Expand Down
26 changes: 16 additions & 10 deletions src/error_log_tool.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,19 @@ print_log(Options, PrintFun, LogFilename) when is_function(PrintFun, 1) ->

print_zlist(Options, PrintFun, LogZList) when is_function(PrintFun, 1) ->
LogZList1=filter(Options,
zlists:ziph(zlists:seq(1, 1000000000000, 1),
LogZList)),
LogZList2=zlists:map(
fun({_N,{NTime,Evt}})->
{_N,{calendar:now_to_universal_time(NTime),Evt}}
end, LogZList1),
zlists:foreach(
fun(E) -> print_evt(PrintFun,E) end,
LogZList2 ).
zlists:ziph(zlists:seq(1, 1000000000000, 1),
LogZList)),
LogZList2=zlists:map(
fun({_N,{NTime,Evt}})->
{_N,{calendar:now_to_universal_time(NTime),Evt}}
end, LogZList1),
case lists:keyfind(limit, 1, Options) of
{limit, Limit} -> LogZList3=zlists:take2(Limit, LogZList2);
false -> LogZList3=LogZList2
end,
zlists:foreach(
fun(E) -> print_evt(PrintFun,E) end,
LogZList3 ).

print_evt(PrintFun, {N, TaggedEvt}) ->
PrintFun(io_lib:format(?REPORT_SEPARATOR, [N])),
Expand Down Expand Up @@ -96,7 +100,9 @@ filter([Opt|Tail]=_Options,LogZList) ->
fun({_N,{_, {_, Node1, {_, _, _}} }})->
Node1 == Node;
(_) -> false
end, LogZList)
end, LogZList);
_ ->
Z=LogZList
end,
filter(Tail,Z).

Expand Down
4 changes: 4 additions & 0 deletions src/error_log_tool_web.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ handle(Req, State) ->
case cowboy_http_req:qs_val(<<"severity">>, Req) of
{undefined,_} -> [];
{Val,_} -> [list_to_atom(binary_to_list(Val))]
end ++
case cowboy_http_req:qs_val(<<"limit">>, Req) of
{undefined,_} -> [];
{Val,_} -> [{limit, list_to_integer(binary_to_list(Val))}]
end,
case cowboy_http_req:qs_val(<<"interval">>, Req) of
{undefined,_} -> Timestamp= logmachine_util:millis_to_now(
Expand Down

0 comments on commit ba8f7f3

Please sign in to comment.