Moved tail cmd to config file
This commit is contained in:
@@ -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}) ->
|
||||
|
||||
@@ -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}}.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user