From ef862220a8c474dca9d3c2f92d4afba9bb84bb0d Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Thu, 1 Feb 2018 09:24:57 -0800 Subject: [PATCH] Don't log when we dropped 0 messages --- src/error_logger_lager_h.erl | 11 ++++++++--- src/lager_file_backend.erl | 17 +++++++++++------ 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index 3755a1d..a3613e2 100644 --- a/src/error_logger_lager_h.erl +++ b/src/error_logger_lager_h.erl @@ -126,9 +126,14 @@ handle_event(Event, #state{sink=Sink, shaper=Shaper} = State) -> end. handle_info({shaper_expired, ?MODULE}, #state{sink=Sink, shaper=Shaper} = State) -> - ?LOGFMT(Sink, warning, self(), - "lager_error_logger_h dropped ~p messages in the last second that exceeded the limit of ~p messages/sec", - [Shaper#lager_shaper.dropped, Shaper#lager_shaper.hwm]), + case Shaper#lager_shaper.dropped of + 0 -> + ok; + Dropped -> + ?LOGFMT(Sink, warning, self(), + "lager_error_logger_h dropped ~p messages in the last second that exceeded the limit of ~p messages/sec", + [Dropped, Shaper#lager_shaper.hwm]) + end, {ok, State#state{shaper=Shaper#lager_shaper{dropped=0, mps=1, lasttime=os:timestamp()}}}; handle_info(_Info, State) -> {ok, State}. diff --git a/src/lager_file_backend.erl b/src/lager_file_backend.erl index 1426f18..5dbbcbc 100644 --- a/src/lager_file_backend.erl +++ b/src/lager_file_backend.erl @@ -193,12 +193,17 @@ handle_info({rotate, File}, #state{name=File,count=Count,date=Date,rotator=Rotat schedule_rotation(File, Date), {ok, State1}; handle_info({shaper_expired, Name}, #state{shaper=Shaper, name=Name, formatter=Formatter, formatter_config=FormatConfig} = State) -> - Report = io_lib:format( - "lager_file_backend dropped ~p messages in the last second that exceeded the limit of ~p messages/sec", - [Shaper#lager_shaper.dropped, Shaper#lager_shaper.hwm]), - ReportMsg = lager_msg:new(Report, warning, [], []), - write(State, lager_msg:timestamp(ReportMsg), - lager_msg:severity_as_int(ReportMsg), Formatter:format(ReportMsg, FormatConfig)), + case Shaper#lager_shaper.dropped of + 0 -> + ok; + Dropped -> + Report = io_lib:format( + "lager_file_backend dropped ~p messages in the last second that exceeded the limit of ~p messages/sec", + [Dropped, Shaper#lager_shaper.hwm]), + ReportMsg = lager_msg:new(Report, warning, [], []), + write(State, lager_msg:timestamp(ReportMsg), + lager_msg:severity_as_int(ReportMsg), Formatter:format(ReportMsg, FormatConfig)) + end, {ok, State#state{shaper=Shaper#lager_shaper{dropped=0, mps=1, lasttime=os:timestamp()}}}; handle_info(_Info, State) -> {ok, State}.