Browse Source

Merge pull request #493 from lukebakken/lrb-windows-rotation

Fix rotation on Windows
pull/494/head
Mark Allen 6 years ago
committed by GitHub
parent
commit
a1ac676949
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions
  1. +1
    -1
      src/lager_file_backend.erl
  2. +11
    -6
      src/lager_rotator_default.erl

+ 1
- 1
src/lager_file_backend.erl View File

@ -190,8 +190,8 @@ handle_event(_Event, State) ->
%% @private
handle_info({rotate, File}, #state{name=File,count=Count,date=Date,rotator=Rotator} = State) ->
_ = Rotator:rotate_logfile(File, Count),
State1 = close_file(State),
_ = Rotator:rotate_logfile(File, Count),
schedule_rotation(File, Date),
{ok, State1};
handle_info({shaper_expired, Name}, #state{shaper=Shaper, name=Name, formatter=Formatter, formatter_config=FormatConfig} = State) ->

+ 11
- 6
src/lager_rotator_default.erl View File

@ -37,6 +37,8 @@ open_logfile(Name, Buffer) ->
Z -> Z
end.
ensure_logfile(Name, undefined, _Inode, Buffer) ->
open_logfile(Name, Buffer);
ensure_logfile(Name, FD, Inode, Buffer) ->
case file:read_file_info(Name) of
{ok, FInfo} ->
@ -80,12 +82,15 @@ rotate_logfile(File, 0) ->
Error ->
Error
end;
rotate_logfile(File, 1) ->
_ = file:rename(File, File++".0"),
rotate_logfile(File, 0);
rotate_logfile(File, Count) ->
_ = file:rename(File ++ "." ++ integer_to_list(Count - 2), File ++ "." ++ integer_to_list(Count - 1)),
rotate_logfile(File, Count - 1).
rotate_logfile(File0, 1) ->
File1 = File0 ++ ".0",
_ = file:rename(File0, File1),
rotate_logfile(File0, 0);
rotate_logfile(File0, Count) ->
File1 = File0 ++ "." ++ integer_to_list(Count - 2),
File2 = File0 ++ "." ++ integer_to_list(Count - 1),
_ = file:rename(File1, File2),
rotate_logfile(File0, Count - 1).
-ifdef(TEST).

Loading…
Cancel
Save