Description and logging

This commit is contained in:
Fabio Salvini 2017-06-11 22:32:55 +02:00
parent ae72db2769
commit 5c920823bb
3 changed files with 4 additions and 5 deletions

View File

@ -1,5 +1,5 @@
{application, log_monitor,
[{description, "An OTP application"},
[{description, "Log monitoring application"},
{vsn, "0.1.0"},
{registered, []},
{mod, { log_monitor_app, []}},

View File

@ -12,8 +12,8 @@ init([]) ->
handle_info({error, File, Text}, []) ->
case send_email(File, Text) of
{error, Reason, Message} ->
io:format("Error sending email: ~s ~p~n", [Reason, Message]);
_ -> io:format("Mail sent~n", [])
error_logger:error_msg("Error sending email: ~s ~p~n", [Reason, Message]);
_ -> ok
end,
{noreply, []}.
@ -36,7 +36,7 @@ send_email(File, Text) ->
Relay = proplists:get_value(relay, EmailConfig),
Username = proplists:get_value(username, EmailConfig),
Password = proplists:get_value(password, EmailConfig),
io:format("Send Email for file ~s with text: ~n~s~n", [File, Text]),
error_logger:info_report("Sending email for file ~s with text: ~n~s~n", [File, Text]),
gen_smtp_client:send_blocking({Sender, [DefaultReceiver],
io_lib:format("Subject: Error notification\r\nFrom: Fabio\r\n\r\nLogfile: ~s~nError: ~n~s~n", [File, Text])},
[{relay, Relay}, {username, Username}, {password, Password}]).

View File

@ -17,7 +17,6 @@ handle_info(Msg, [SupPid, Port]) ->
GathererPid ! {log_line, Text},
{noreply, [SupPid, Port]};
{Port, {exit_status, _Status}} ->
io:format("Watcher terminated~n"),
{stop, tail_exit, []}
end.