Skip to content

Commit 3d61650

Browse files
author
Mark Allen
authored
Merge pull request erlang-lager#475 from russagit/master
Fix check_hwm
2 parents 1720218 + 370c909 commit 3d61650

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

‎src/error_logger_lager_h.erl‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,11 @@ no_silent_hwm_drops_test_() ->
624624
[error_logger:error_msg("Foo ~p~n", [K]) || K <- lists:seq(1, 15)],
625625
timer:sleep(1000),
626626
lager_handler_watcher:pop_until("lager_error_logger_h dropped 10 messages in the last second that exceeded the limit of 5 messages/sec",
627+
fun lists:flatten/1),
628+
%and once again
629+
[error_logger:error_msg("Foo1 ~p~n", [K]) || K <- lists:seq(1, 20)],
630+
timer:sleep(1000),
631+
lager_handler_watcher:pop_until("lager_error_logger_h dropped 16 messages in the last second that exceeded the limit of 5 messages/sec",
627632
fun lists:flatten/1)
628633
after
629634
application:stop(lager),

‎src/lager_util.erl‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,15 @@ check_hwm(Shaper = #lager_shaper{filter = Filter}, Event) ->
501501

502502
check_hwm(Shaper = #lager_shaper{hwm = undefined}) ->
503503
{true, 0, Shaper};
504-
check_hwm(Shaper = #lager_shaper{mps = Mps, hwm = Hwm}) when Mps < Hwm ->
505-
%% haven't hit high water mark yet, just log it
506-
{true, 0, Shaper#lager_shaper{mps=Mps+1, lasttime = os:timestamp()}};
504+
check_hwm(Shaper = #lager_shaper{mps = Mps, hwm = Hwm, lasttime = Last}) when Mps < Hwm ->
505+
{M, S, _} = Now = os:timestamp(),
506+
case Last of
507+
{M, S, _} ->
508+
{true, 0, Shaper#lager_shaper{mps=Mps+1}};
509+
_ ->
510+
%different second - reset mps
511+
{true, 0, Shaper#lager_shaper{mps=1, lasttime = Now}}
512+
end;
507513
check_hwm(Shaper = #lager_shaper{lasttime = Last, dropped = Drop}) ->
508514
%% are we still in the same second?
509515
{M, S, _} = Now = os:timestamp(),

0 commit comments

Comments
 (0)