diff --git a/apps/log_monitor/src/coordinator.erl b/apps/log_monitor/src/coordinator.erl index 48bcc8a..f63125f 100644 --- a/apps/log_monitor/src/coordinator.erl +++ b/apps/log_monitor/src/coordinator.erl @@ -1,6 +1,8 @@ -module(coordinator). -behaviour(supervisor). --compile(export_all). + +-export([start_link/0]). +-export([init/1]). start_link() -> supervisor:start_link(?MODULE, []). @@ -12,14 +14,13 @@ init([]) -> start => {mailer, start_link, []}, restart => permanent, shutdown => 5000 - }] ++ monitors_child_specs(), + }, + #{ + id => logfiles_sup, + start => {logfiles_sup, start_link, []}, + restart => permanent, + type => supervisor, + shutdown => 5000 + } + ], {ok, {SupFlags, ChildSpecs}}. - -monitors_child_specs() -> - {ok, Files} = application:get_env(log_monitor, logfiles), - [#{ - id => list_to_atom(File), - start => {monitor, start_link, [File]}, - restart => temporary, - shutdown => 5000 - } || File <- Files]. diff --git a/apps/log_monitor/src/gatherer.erl b/apps/log_monitor/src/gatherer.erl index b6263a5..c52210f 100644 --- a/apps/log_monitor/src/gatherer.erl +++ b/apps/log_monitor/src/gatherer.erl @@ -1,6 +1,9 @@ -module(gatherer). -behaviour(gen_server). --compile(export_all). + +-export([start_link/1, init/1, terminate/2]). +-export([handle_info/2, handle_cast/2, handle_call/3]). +-export([code_change/3]). start_link(File) -> gen_server:start_link(?MODULE, [File], []). diff --git a/apps/log_monitor/src/logfiles_sup.erl b/apps/log_monitor/src/logfiles_sup.erl new file mode 100644 index 0000000..e9ec2ec --- /dev/null +++ b/apps/log_monitor/src/logfiles_sup.erl @@ -0,0 +1,25 @@ +-module(logfiles_sup). +-behaviour(supervisor). + +-export([start_link/0]). +-export([init/1]). + +start_link() -> + supervisor:start_link({local, logfiles_sup}, ?MODULE, []). + +init([]) -> + SupFlags = #{ + strategy => simple_one_for_one, + intensity => 0, + period => 1 + }, + ChildSpecs = [#{ + id => monitor, + start => {monitor, start_link, []}, + restart => temporary, + shutdown => 5000 + }], + {ok, {SupFlags, ChildSpecs}}. + +%% Start monitor with: +%% supervisor:start_child(logfiles_sup, "/tmp/lines.log") diff --git a/apps/log_monitor/src/mailer.erl b/apps/log_monitor/src/mailer.erl index dfc05b8..4617299 100644 --- a/apps/log_monitor/src/mailer.erl +++ b/apps/log_monitor/src/mailer.erl @@ -1,6 +1,9 @@ -module(mailer). -behaviour(gen_server). --compile(export_all). + +-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, [], []). diff --git a/apps/log_monitor/src/monitor.erl b/apps/log_monitor/src/monitor.erl index 0652757..126fd7e 100644 --- a/apps/log_monitor/src/monitor.erl +++ b/apps/log_monitor/src/monitor.erl @@ -1,6 +1,8 @@ -module(monitor). -behaviour(supervisor). --compile(export_all). + +-export([start_link/1]). +-export([init/1]). start_link(File) -> supervisor:start_link(?MODULE, [File]). diff --git a/apps/log_monitor/src/watcher.erl b/apps/log_monitor/src/watcher.erl index 8496373..a6eb18b 100644 --- a/apps/log_monitor/src/watcher.erl +++ b/apps/log_monitor/src/watcher.erl @@ -1,6 +1,9 @@ -module(watcher). -behaviour(gen_server). --compile(export_all). + +-export([start_link/2, init/1, terminate/2]). +-export([handle_info/2, handle_cast/2, handle_call/3]). +-export([code_change/3]). start_link(SupPid, File) -> gen_server:start_link(?MODULE, [SupPid, File], []). diff --git a/config/sys.config b/config/sys.config index 889f6c9..eb7bcfa 100644 --- a/config/sys.config +++ b/config/sys.config @@ -1,7 +1,6 @@ [ { log_monitor, [ - {logfiles, ["/tmp/lines.log", "/tmp/lines2.log"]}, {email_config, [ {sender, "me@example.com"},