log_monitor/apps/log_monitor/src/log_sup.erl

73 lines
2.4 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(log_sup).
-behaviour(supervisor).
%% API
-export([start_link/2]).
%% Supervisor callbacks
-export([init/1]).
-define(SERVER, ?MODULE).
%%%===================================================================
%%% API functions
%%%===================================================================
%%--------------------------------------------------------------------
%% @doc
%% Starts the supervisor
%%
%% @spec start_link(File, ErrorRegex) -> {ok, Pid} | ignore | {error, Error}
%% @end
%%--------------------------------------------------------------------
start_link(File, ErrorRegex) ->
supervisor:start_link(?MODULE, [File, ErrorRegex]).
%%%===================================================================
%%% 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([File, ErrorRegex]) ->
SupFlags = #{strategy => one_for_one},
ChildSpecs = [#{
id => gatherer,
start => {gatherer, start_link, [File, ErrorRegex]},
restart => permanent,
shutdown => 5000,
modules => [gatherer]
},
#{
id => watcher,
start => {watcher, start_link, [self(), File]},
restart => permanent,
shutdown => 5000,
modules => [watcher]
}],
{ok, {SupFlags, ChildSpecs}}.
%%%===================================================================
%%% Internal functions
%%%===================================================================