From 5c920823bb36ff19160057d78dbc4092ce8bb092 Mon Sep 17 00:00:00 2001 From: Fabio Salvini Date: Sun, 11 Jun 2017 22:32:55 +0200 Subject: [PATCH] Description and logging --- apps/log_monitor/src/log_monitor.app.src | 2 +- apps/log_monitor/src/mailer.erl | 6 +++--- apps/log_monitor/src/watcher.erl | 1 - 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/log_monitor/src/log_monitor.app.src b/apps/log_monitor/src/log_monitor.app.src index db8f29a..9f87177 100644 --- a/apps/log_monitor/src/log_monitor.app.src +++ b/apps/log_monitor/src/log_monitor.app.src @@ -1,5 +1,5 @@ {application, log_monitor, - [{description, "An OTP application"}, + [{description, "Log monitoring application"}, {vsn, "0.1.0"}, {registered, []}, {mod, { log_monitor_app, []}}, diff --git a/apps/log_monitor/src/mailer.erl b/apps/log_monitor/src/mailer.erl index f8dbaff..dfc05b8 100644 --- a/apps/log_monitor/src/mailer.erl +++ b/apps/log_monitor/src/mailer.erl @@ -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}]). diff --git a/apps/log_monitor/src/watcher.erl b/apps/log_monitor/src/watcher.erl index 417630c..f80ed90 100644 --- a/apps/log_monitor/src/watcher.erl +++ b/apps/log_monitor/src/watcher.erl @@ -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.