diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index c2c6465..e04a714 100644 --- a/src/error_logger_lager_h.erl +++ b/src/error_logger_lager_h.erl @@ -622,6 +622,11 @@ no_silent_hwm_drops_test_() -> [error_logger:error_msg("Foo ~p~n", [K]) || K <- lists:seq(1, 15)], timer:sleep(1000), lager_handler_watcher:pop_until("lager_error_logger_h dropped 10 messages in the last second that exceeded the limit of 5 messages/sec", + fun lists:flatten/1), + %and once again + [error_logger:error_msg("Foo1 ~p~n", [K]) || K <- lists:seq(1, 20)], + timer:sleep(1000), + lager_handler_watcher:pop_until("lager_error_logger_h dropped 16 messages in the last second that exceeded the limit of 5 messages/sec", fun lists:flatten/1) after application:stop(lager), diff --git a/src/lager_util.erl b/src/lager_util.erl index 4c75c8f..df9ab57 100644 --- a/src/lager_util.erl +++ b/src/lager_util.erl @@ -504,9 +504,15 @@ check_hwm(Shaper = #lager_shaper{filter = Filter}, Event) -> check_hwm(Shaper = #lager_shaper{hwm = undefined}) -> {true, 0, Shaper}; -check_hwm(Shaper = #lager_shaper{mps = Mps, hwm = Hwm}) when Mps < Hwm -> - %% haven't hit high water mark yet, just log it - {true, 0, Shaper#lager_shaper{mps=Mps+1, lasttime = os:timestamp()}}; +check_hwm(Shaper = #lager_shaper{mps = Mps, hwm = Hwm, lasttime = Last}) when Mps < Hwm -> + {M, S, _} = Now = os:timestamp(), + case Last of + {M, S, _} -> + {true, 0, Shaper#lager_shaper{mps=Mps+1}}; + _ -> + %different second - reset mps + {true, 0, Shaper#lager_shaper{mps=1, lasttime = Now}} + end; check_hwm(Shaper = #lager_shaper{lasttime = Last, dropped = Drop}) -> %% are we still in the same second? {M, S, _} = Now = os:timestamp(),