Keep total log file count in check

This commit is contained in:
Craig Everett 2020-01-31 17:20:26 +09:00
parent b08556f0f5
commit d60304be49
49 changed files with 43 additions and 24 deletions

View File

@ -1 +1 @@
0.10.3
0.10.4

View File

@ -1,6 +1,6 @@
{application,zx,
[{description,"An Erlang development tool and Zomp user client"},
{vsn,"0.10.3"},
{vsn,"0.10.4"},
{applications,[stdlib,kernel]},
{modules,[zx,zx_auth,zx_conn,zx_conn_sup,zx_daemon,zx_key,
zx_lib,zx_local,zx_net,zx_peer,zx_peer_man,

View File

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -24,7 +24,7 @@
%%% @end
-module(zx).
-vsn("0.10.3").
-vsn("0.10.4").
-behavior(application).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
@ -420,6 +420,8 @@ start() ->
zx_lib:new_logpath({"otpr", "zx", Version})
end,
ok = logger:remove_handler(default),
LogDir = filename:dirname(LogPath),
ok = trim_logs(LogDir),
LoggerConf =
#{config =>
#{burst_limit_enable => true,
@ -455,6 +457,21 @@ start() ->
ok = log(info, "Available package types: ~w", [Types]),
application:ensure_started(zx, permanent).
trim_logs(LogDir) ->
{ok, Files} = file:list_dir(LogDir),
TS = fun(Name) -> hd(string:split(Name, ".")) end,
Prefixes = ordsets:from_list(lists:map(TS, Files)),
Length = length(Prefixes),
case Length > 10 of
true ->
Old = lists:sublist(Prefixes, Length - 10),
Mark = fun(Prefix) -> filelib:wildcard(Prefix ++ ".*", LogDir) end,
Marked = lists:append(lists:map(Mark, Old)),
lists:foreach(fun file:delete/1, Marked);
false ->
ok
end.
-spec stop() -> ok | {error, Reason :: term()}.
%% @doc

View File

@ -9,7 +9,7 @@
%%% @end
-module(zx_auth).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -7,7 +7,7 @@
%%% @end
-module(zx_conn).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_conn_sup).
-vsn("0.10.3").
-vsn("0.10.4").
-behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -138,7 +138,7 @@
%%% @end
-module(zx_daemon).
-vsn("0.10.3").
-vsn("0.10.4").
-behavior(gen_server).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
@ -1690,10 +1690,12 @@ do_build(PackageID) ->
%% Keep (the highly uncertain) build procedure separate from the zx_daemon, but
%% still sequentialized by it.
make(PackageID) ->
Dirs = [zx_lib:ppath(D, PackageID) || D <- [etc, var, tmp, log, lib]],
make(PackageID = {Realm, Name, _}) ->
Dirs = [zx_lib:path(D, Realm, Name) || D <- [etc, var, tmp, log]],
ok = lists:foreach(fun zx_lib:force_dir/1, Dirs),
ok = file:set_cwd(zx_lib:ppath(lib, PackageID)),
LibDir = zx_lib:ppath(lib, PackageID),
ok = zx_lib:force_dir(LibDir),
ok = file:set_cwd(LibDir),
Result = zx_lib:build(),
zx_daemon ! {self(), Result}.

View File

@ -8,7 +8,7 @@
%%% @end
-module(zx_key).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -10,7 +10,7 @@
%%% @end
-module(zx_lib).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -6,7 +6,7 @@
%%% @end
-module(zx_local).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_net).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -8,7 +8,7 @@
%%% @end
-module(zx_peer).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -9,7 +9,7 @@
%%% @end
-module(zx_peer_man).
-vsn("0.10.3").
-vsn("0.10.4").
-behavior(gen_server).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -6,7 +6,7 @@
%%% @end
-module(zx_peer_sup).
-vsn("0.10.3").
-vsn("0.10.4").
-behaviour(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -10,7 +10,7 @@
%%% @end
-module(zx_peers).
-vsn("0.10.3").
-vsn("0.10.4").
-behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_proxy).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_sup).
-vsn("0.10.3").
-vsn("0.10.4").
-behavior(supervisor).
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").

View File

@ -6,7 +6,7 @@
%%% @end
-module(zx_tty).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -5,7 +5,7 @@
%%% @end
-module(zx_userconf).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -7,7 +7,7 @@
%%% @end
-module(zx_zsp).
-vsn("0.10.3").
-vsn("0.10.4").
-author("Craig Everett <zxq9@zxq9.com>").
-copyright("Craig Everett <zxq9@zxq9.com>").
-license("GPL-3.0").

View File

@ -9,7 +9,7 @@
{license,"MIT"}.
{modules,[]}.
{name,"zx"}.
{package_id,{"otpr","zx",{0,10,3}}}.
{package_id,{"otpr","zx",{0,10,4}}}.
{prefix,"zx_"}.
{repo_url,"https://gitlab.com/zxq9/zx"}.
{tags,["tools","package manager","erlang"]}.