fix logger
This commit is contained in:
parent
b274b48e3d
commit
3b46f8fba4
@ -13,6 +13,7 @@
|
||||
|
||||
%% API
|
||||
-export([start_link/1, start_link/2, write/2]).
|
||||
-export([archive_file/1]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
|
||||
@ -89,12 +90,7 @@ handle_cast({write, Data}, State = #state{file = {OldIoDevice, OldFilePath}, que
|
||||
true ->
|
||||
ok = file:close(OldIoDevice),
|
||||
%% 归档
|
||||
erlang:spawn(fun() ->
|
||||
%% 压缩文件
|
||||
ok = erl_tar:create(OldFilePath ++ ".tar", [OldFilePath], [compressed]),
|
||||
%% 删除原来的文件
|
||||
ok = file:delete(OldFilePath)
|
||||
end),
|
||||
erlang:spawn(fun() -> archive_file(OldFilePath) end),
|
||||
|
||||
%% 开启新的文件
|
||||
NewFilePath = make_file(FileName, NDate),
|
||||
@ -190,3 +186,16 @@ maybe_new_file({Y, M, D}, {Y0, M0, D0}) ->
|
||||
% FilePath = make_file(FileName, Date),
|
||||
% filelib:is_file(FilePath) andalso file:delete(FilePath)
|
||||
% end, lists:seq(1, 10)).
|
||||
|
||||
|
||||
-spec archive_file(FilePath :: string()) -> ok.
|
||||
archive_file(FilePath) when is_list(FilePath) ->
|
||||
TarFile = FilePath ++ ".tar",
|
||||
{ok, Tar} = erl_tar:open(TarFile, [write, compressed]),
|
||||
BaseName = filename:basename(FilePath),
|
||||
{ok, Data} = file:read_file(FilePath),
|
||||
|
||||
ok = erl_tar:add(Tar, Data, BaseName, []),
|
||||
ok = erl_tar:close(Tar),
|
||||
%% 删除原来的文件
|
||||
ok = file:delete(FilePath).
|
||||
Loading…
x
Reference in New Issue
Block a user