log_monitor/apps/log_monitor/src/logfiles_sup.erl

93 lines
2.7 KiB
Erlang

%%%-------------------------------------------------------------------
%%% @author Fabio Salvini <fs@fabiosalvini.com>
%%% @copyright (C) 2017, Fabio Salvini
%%% @doc
%%%
%%% @end
%%% Created : 2 Jul 2017 by Fabio Salvini <fs@fabiosalvini.com>
%%%-------------------------------------------------------------------
-module(logfiles_sup).
-behaviour(supervisor).
%% API
-export([start_link/0]).
-export([add_child/1, remove_child/1]).
%% Supervisor callbacks
-export([init/1]).
-define(SERVER, ?MODULE).
%%%===================================================================
%%% API functions
%%%===================================================================
%%--------------------------------------------------------------------
%% @doc
%% Starts the supervisor
%%
%% @spec start_link() -> {ok, Pid} | ignore | {error, Error}
%% @end
%%--------------------------------------------------------------------
start_link() ->
supervisor:start_link({local, ?SERVER}, ?MODULE, []).
%%--------------------------------------------------------------------
%% @doc
%% Add a child to the supervisor
%%
%% @spec add_child(Args) -> void()
%% @end
%%--------------------------------------------------------------------
add_child(Args = [File, _ErrorRegex]) ->
supervisor:start_child(
?MODULE,
#{
id => File,
start => {log_sup, start_link, Args},
restart => temporary,
shutdown => 5000,
modules => [log_sup]
}
).
%%--------------------------------------------------------------------
%% @doc
%% Remove a child from the supervisor
%%
%% @spec remove_child(File) -> void()
%% @end
%%--------------------------------------------------------------------
remove_child(File) ->
supervisor:terminate_child(?MODULE, File).
%%%===================================================================
%%% Supervisor callbacks
%%%===================================================================
%%--------------------------------------------------------------------
%% @private
%% @doc
%% Whenever a supervisor is started using supervisor:start_link/[2,3],
%% this function is called by the new process to find out about
%% restart strategy, maximum restart intensity, and child
%% specifications.
%%
%% @spec init(Args) -> {ok, {SupFlags, [ChildSpec]}} |
%% ignore |
%% {error, Reason}
%% @end
%%--------------------------------------------------------------------
init([]) ->
SupFlags = #{
strategy => one_for_one,
intensity => 0,
period => 1
},
ChildSpecs = [],
{ok, {SupFlags, ChildSpecs}}.
%%%===================================================================
%%% Internal functions
%%%===================================================================