Browse Source

Enhancements to previous commit: cleanup fd and always keep rotating

pull/475/head
Andrew Thompson 6 years ago
parent
commit
81b5c61bd0
1 changed files with 4 additions and 7 deletions
  1. +4
    -7
      src/lager_rotator_default.erl

+ 4
- 7
src/lager_rotator_default.erl View File

@ -74,18 +74,15 @@ ensure_logfile(Name, FD, Inode, Buffer) ->
rotate_logfile(File, 0) -> rotate_logfile(File, 0) ->
%% open the file in write-only mode to truncate/create it %% open the file in write-only mode to truncate/create it
case file:open(File, [write]) of case file:open(File, [write]) of
{ok, _FD} ->
{ok, FD} ->
file:close(FD),
ok; ok;
Error -> Error ->
Error Error
end; end;
rotate_logfile(File, 1) -> rotate_logfile(File, 1) ->
case file:rename(File, File++".0") of
ok ->
rotate_logfile(File, 0);
Error ->
Error
end;
_ = file:rename(File, File++".0"),
rotate_logfile(File, 0);
rotate_logfile(File, Count) -> rotate_logfile(File, Count) ->
_ = file:rename(File ++ "." ++ integer_to_list(Count - 2), File ++ "." ++ integer_to_list(Count - 1)), _ = file:rename(File ++ "." ++ integer_to_list(Count - 2), File ++ "." ++ integer_to_list(Count - 1)),
rotate_logfile(File, Count - 1). rotate_logfile(File, Count - 1).

Loading…
Cancel
Save