Moved constants to configuration file
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
terminate/2, code_change/3]).
|
||||
|
||||
-define(SERVER, ?MODULE).
|
||||
-define(DEFAULT_TIMER_TIME, 1000).
|
||||
-define(DEFAULT_SAFE_TIMER_TIME, 30000).
|
||||
|
||||
-record(log, {file, error_regex}).
|
||||
%% -record(state, {}).
|
||||
@@ -100,8 +102,8 @@ handle_cast(_Msg, State) ->
|
||||
handle_info({log_line, Text}, [off, Log = #log{error_regex = ErrorRegex}]) ->
|
||||
case isError(Text, ErrorRegex) of
|
||||
true ->
|
||||
{ok, Timer} = timer:send_after(1000, {timeout}),
|
||||
{ok, SafeTimer} = timer:send_after(30000, {timeout}),
|
||||
{ok, Timer} = timer:send_after(timer_time(), {timeout}),
|
||||
{ok, SafeTimer} = timer:send_after(safe_timer_time(), {timeout}),
|
||||
{noreply, [on, Log, Text, Timer, SafeTimer]};
|
||||
false -> {noreply, [off, Log]}
|
||||
end;
|
||||
@@ -109,7 +111,7 @@ handle_info({log_line, Text}, [on, Log = #log{error_regex = ErrorRegex}, Error,
|
||||
case isError(Text, ErrorRegex) of
|
||||
true ->
|
||||
timer:cancel(Timer),
|
||||
{ok, NewTimer} = timer:send_after(1000, {timeout}),
|
||||
{ok, NewTimer} = timer:send_after(timer_time(), {timeout}),
|
||||
{noreply, [on, Log, Error ++ Text, NewTimer, SafeTimer]};
|
||||
false ->
|
||||
{noreply, [on, Log, Error ++ Text, Timer, SafeTimer]}
|
||||
@@ -155,3 +157,11 @@ isError(Text, ErrorRegex) ->
|
||||
nomatch ->
|
||||
false
|
||||
end.
|
||||
|
||||
timer_time() ->
|
||||
{ok, ProcessingConfig} = application:get_env(log_monitor, processing_config),
|
||||
proplists:get_value(gathering_time, ProcessingConfig, ?DEFAULT_TIMER_TIME).
|
||||
|
||||
safe_timer_time() ->
|
||||
{ok, ProcessingConfig} = application:get_env(log_monitor, processing_config),
|
||||
proplists:get_value(max_gathering_time, ProcessingConfig, ?DEFAULT_TIMER_TIME).
|
||||
|
||||
Reference in New Issue
Block a user