diff --git a/apps/log_monitor/src/gatherer.erl b/apps/log_monitor/src/gatherer.erl index dba78ec..5cb8bbe 100644 --- a/apps/log_monitor/src/gatherer.erl +++ b/apps/log_monitor/src/gatherer.erl @@ -82,8 +82,8 @@ init([File, ErrorRegex]) -> state_off({log_line, Text}, State = #state_off{log = Log}) -> case isError(Text, Log#log.error_regex) of true -> - Timeout = timer_time(), - MaxTimeout = safe_timer_time(), + Timeout = gathering_time(), + MaxTimeout = max_gathering_time(), Now = to_milliseconds(os:timestamp()), Until = Now + Timeout, MaxUntil = Now + MaxTimeout, @@ -112,7 +112,7 @@ state_off({log_line, Text}, State = #state_off{log = Log}) -> state_on({log_line, Text}, #state_on{log = Log, error = Error, until = Until, max_until = MaxUntil}) -> case isError(Text, Log#log.error_regex) of true -> - Timeout = timer_time(), + Timeout = gathering_time(), Now = to_milliseconds(os:timestamp()), NewUntil = min(Now + Timeout, MaxUntil), {next_state, @@ -220,12 +220,12 @@ isError(Text, ErrorRegex) -> false end. -timer_time() -> - {ok, ProcessingConfig} = application:get_env(log_monitor, processing_config), +gathering_time() -> + {ok, ProcessingConfig} = application:get_env(log_monitor, general), proplists:get_value(gathering_time, ProcessingConfig, ?DEFAULT_TIMER_TIME). -safe_timer_time() -> - {ok, ProcessingConfig} = application:get_env(log_monitor, processing_config), +max_gathering_time() -> + {ok, ProcessingConfig} = application:get_env(log_monitor, general), proplists:get_value(max_gathering_time, ProcessingConfig, ?DEFAULT_TIMER_TIME). to_milliseconds({Me, S, Mu}) -> diff --git a/apps/log_monitor/src/watcher.erl b/apps/log_monitor/src/watcher.erl index 1ae2a05..dfdcd4c 100644 --- a/apps/log_monitor/src/watcher.erl +++ b/apps/log_monitor/src/watcher.erl @@ -18,7 +18,6 @@ terminate/2, code_change/3]). -define(SERVER, ?MODULE). --define(TAIL_CMD, "/usr/bin/tail -n0 --follow=name "). -record(state, {file, supervisor, port}). @@ -54,7 +53,9 @@ start_link(SupPid, File) -> init([SupPid, File]) -> timer:sleep(1000), config ! {watcher_init, File}, - Cmd = ?TAIL_CMD ++ File, + {ok, GeneralConfig} = application:get_env(log_monitor, general), + TailCmd = proplists:get_value(tail_cmd, GeneralConfig), + Cmd = TailCmd ++ " " ++ File, Port = open_port({spawn, Cmd}, [stderr_to_stdout, exit_status, binary]), {ok, #state{file = File, supervisor = SupPid, port = Port}}. diff --git a/config/log_monitor.config b/config/log_monitor.config index cd82f8d..a396883 100644 --- a/config/log_monitor.config +++ b/config/log_monitor.config @@ -1,6 +1,21 @@ [ { log_monitor, [ + {general, + [ + %% Command to watch the log files. + {tail_cmd, "/usr/bin/tail -n0 --follow=name"}, + + %% How long to gather log lines after an error occurs. + %% If another error occurs, the time is reset. + {gathering_time, 1000}, + + %% Max time for gathering log lines. + %% Precaution in case of infinite consecutive errors. + {max_gathering_time, 30000} + ] + }, + {email_config, [ {sender, "log@monitor.com"}, @@ -24,17 +39,6 @@ } ] }, - {processing_config, - [ - %% How long to gather log lines after an error occurs. - %% If another error occurs, the time is reset. - {gathering_time, 1000}, - - %% Max time for gathering log lines. - %% Precaution in case of infinite consecutive errors. - {max_gathering_time, 30000} - ] - }, %% Location of the file that contains the logs to monitor. {logfiles_config, "/home/fsalvini/gitRepos/log_monitor/config/logfiles.config"}