Skip to content

Commit

Permalink
Merge pull request #568 from outddd/master
Browse files Browse the repository at this point in the history
Save state with new logfile handle when drop logs in shaper_expired
  • Loading branch information
jadeallenx authored Aug 11, 2022
2 parents d255955 + 9dce2ae commit fb340d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/lager_file_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ handle_info({rotate, File}, #state{name=File, count=Count, date=Date, rotator=Ro
schedule_rotation(File, Date),
{ok, State1};
handle_info({shaper_expired, Name}, #state{shaper=Shaper, name=Name, formatter=Formatter, formatter_config=FormatConfig} = State) ->
_ = case Shaper#lager_shaper.dropped of
State1 = case Shaper#lager_shaper.dropped of
0 ->
ok;
State;
Dropped ->
Report = io_lib:format(
"lager_file_backend dropped ~p messages in the last second that exceeded the limit of ~p messages/sec",
Expand All @@ -208,7 +208,7 @@ handle_info({shaper_expired, Name}, #state{shaper=Shaper, name=Name, formatter=F
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=0, lasttime=os:timestamp()}}};
{ok, State1#state{shaper=Shaper#lager_shaper{dropped=0, mps=0, lasttime=os:timestamp()}}};
handle_info(_Info, State) ->
{ok, State}.

Expand Down Expand Up @@ -248,8 +248,8 @@ write(#state{name=Name, fd=FD,
%% need to check for rotation
Buffer = {State0#state.sync_size, State0#state.sync_interval},
case Rotator:ensure_logfile(Name, FD, Inode, Ctime, Buffer) of
{ok, {_FD, _Inode, _Ctime, Size}} when RotSize > 0, Size > RotSize ->
State1 = close_file(State0),
{ok, {NewFD, NewInode, NewCtime, Size}} when RotSize > 0, Size > RotSize ->
State1 = close_file(State0#state{fd=NewFD, inode=NewInode, ctime=NewCtime}),
case Rotator:rotate_logfile(Name, Count) of
ok ->
%% go around the loop again, we'll do another rotation check and hit the next clause of ensure_logfile
Expand Down
2 changes: 1 addition & 1 deletion src/lager_rotator_default.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ reopen_logfile(Name, FD0, Buffer) ->
_ = file:close(FD0),
_ = file:close(FD0),
case open_logfile(Name, Buffer) of
{ok, {_FD1, _Inode, _Size, _Ctime}=FileInfo} ->
{ok, {_FD1, _Inode, _Ctime, _Size}=FileInfo} ->
%% inode changed, file was probably moved and
%% recreated
{ok, FileInfo};
Expand Down

0 comments on commit fb340d7

Please sign in to comment.