diff --git a/apps/log_monitor/src/mailer.erl b/apps/log_monitor/src/mailer.erl index 9c917ca..446277d 100644 --- a/apps/log_monitor/src/mailer.erl +++ b/apps/log_monitor/src/mailer.erl @@ -186,7 +186,7 @@ send_email(File, Text) -> -> [DefaultReceiver]; true -> GroupReceivers end, - Subject = email_subject(RawSubject, File, lists:takewhile(fun(X) -> X =/= "\n" end, Text)), + Subject = email_subject(RawSubject, File, first_line(Text)), error_logger:info_msg( "Sending email [~n\tSender: ~s,~n\tReceivers: ~s,~n\tSubject: ~s,~n\tFile: ~s~n]~n", [Sender, lists:join(",", Receivers), Subject, File] @@ -250,6 +250,9 @@ file_name_from_path(File) -> {match, [_, _, Basename]} = re:run(File, "^(.*\/)?(.*)\\..*$", [{capture, all, list}]), Basename. +first_line(Text) -> + lists:takewhile(fun(X) -> X =/= 10 end, Text). %% 10: newline + %%%=================================================================== %%% Tests %%%=================================================================== @@ -274,4 +277,9 @@ file_name_from_path_test() -> ?assertEqual("myApp", file_name_from_path("./myApp.log")), ?assertEqual("myApp", file_name_from_path("/var/log/myApp.log")). +first_line_test() -> + ?assertEqual("", first_line("")), + ?assertEqual("Line", first_line("Line")), + ?assertEqual("Line", first_line("Line\nLine")). + -endif.