Renamed monitor module to log_sup and added config module
This commit is contained in:
parent
3ea2c5c55e
commit
2a80282b8e
34
apps/log_monitor/src/config.erl
Normal file
34
apps/log_monitor/src/config.erl
Normal file
|
@ -0,0 +1,34 @@
|
|||
-module(config).
|
||||
-behaviour(gen_server).
|
||||
|
||||
-export([monitor_log/1]).
|
||||
-export([start_link/0, init/1, terminate/2]).
|
||||
-export([handle_info/2, handle_cast/2, handle_call/3]).
|
||||
-export([code_change/3]).
|
||||
|
||||
start_link() ->
|
||||
gen_server:start_link(?MODULE, [], []).
|
||||
|
||||
init([]) ->
|
||||
register(config, self()),
|
||||
{ok, []}.
|
||||
|
||||
handle_info(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
handle_cast(_Msg, State) ->
|
||||
{noreply, State}.
|
||||
|
||||
handle_call({monitor, Path}, _From, State) ->
|
||||
supervisor:start_child(logfiles_sup, [Path]),
|
||||
{reply, ok, State}.
|
||||
|
||||
terminate(_Reason, _State) ->
|
||||
shutdown.
|
||||
|
||||
code_change(_OldVsn, State, _Extra) ->
|
||||
{ok, State}.
|
||||
|
||||
monitor_log(Path) ->
|
||||
config ! {monitor, Path},
|
||||
gen_server:call(config, {monitor, Path}).
|
|
@ -21,6 +21,12 @@ init([]) ->
|
|||
restart => permanent,
|
||||
type => supervisor,
|
||||
shutdown => 5000
|
||||
},
|
||||
#{
|
||||
id => config,
|
||||
start => {config, start_link, []},
|
||||
restart => permanent,
|
||||
shutdown => 5000
|
||||
}
|
||||
],
|
||||
{ok, {SupFlags, ChildSpecs}}.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
-module(monitor).
|
||||
-module(log_sup).
|
||||
-behaviour(supervisor).
|
||||
|
||||
-export([start_link/1]).
|
|
@ -5,7 +5,7 @@
|
|||
-export([init/1]).
|
||||
|
||||
start_link() ->
|
||||
supervisor:start_link({local, logfiles_sup}, ?MODULE, []).
|
||||
supervisor:start_link({local, ?MODULE}, ?MODULE, []).
|
||||
|
||||
init([]) ->
|
||||
SupFlags = #{
|
||||
|
@ -14,12 +14,9 @@ init([]) ->
|
|||
period => 1
|
||||
},
|
||||
ChildSpecs = [#{
|
||||
id => monitor,
|
||||
start => {monitor, start_link, []},
|
||||
id => log_sup,
|
||||
start => {log_sup, start_link, []},
|
||||
restart => temporary,
|
||||
shutdown => 5000
|
||||
}],
|
||||
{ok, {SupFlags, ChildSpecs}}.
|
||||
|
||||
%% Start monitor with:
|
||||
%% supervisor:start_child(logfiles_sup, "/tmp/lines.log")
|
||||
|
|
Loading…
Reference in New Issue
Block a user