From 4e2445486e6aa461057a0fb4b2c31590acd6258d Mon Sep 17 00:00:00 2001 From: Markus Kreth Date: Thu, 21 Nov 2019 23:11:35 +0100 Subject: [PATCH] log to temp file. --- .../vaadinclubhelper/email/MuttEmailCommand.java | 4 ++-- .../ui/navigation/SendEmails.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/email/MuttEmailCommand.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/email/MuttEmailCommand.java index 9d75abe..862f4e7 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/email/MuttEmailCommand.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/email/MuttEmailCommand.java @@ -18,7 +18,7 @@ public class MuttEmailCommand implements EmailCommand { final List arguments = createArguments(email); final List errors = new ArrayList<>(); - File log = new File("email.log"); + File log = File.createTempFile("email_output", ".log"); List adresses = email.getEmails(); for (String adress : adresses) { List builders = new ArrayList<>(); @@ -50,7 +50,7 @@ public class MuttEmailCommand implements EmailCommand { } if (errors.isEmpty() == false) { - throw new RuntimeException("Errors: " + errors); + throw new EmailException("Fehler beim Senden. Log File: " + log.getAbsolutePath(), errors); } } diff --git a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/SendEmails.java b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/SendEmails.java index 3e63a5e..f211d74 100644 --- a/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/SendEmails.java +++ b/src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/SendEmails.java @@ -10,6 +10,8 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; import com.vaadin.data.HasValue.ValueChangeEvent; @@ -36,11 +38,14 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person; import de.kreth.vaadin.clubhelper.vaadinclubhelper.email.Email; import de.kreth.vaadin.clubhelper.vaadinclubhelper.email.EmailCommand; +import de.kreth.vaadin.clubhelper.vaadinclubhelper.email.EmailException; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.ClubhelperMenuBar; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.MenuItemStateFactory; public class SendEmails extends VerticalLayout implements View { + private static final Logger LOGGER = LoggerFactory.getLogger(SendEmails.class); + private PersonBusiness personBusiness; private List allGroups; @@ -141,6 +146,7 @@ public class SendEmails extends VerticalLayout implements View { .setMessage(body.getValue()) .addEmails(adresses) .build(); + LOGGER.info("Versende an {}: {}", adresses, email); try { emailCommand.send(email); } @@ -149,6 +155,15 @@ public class SendEmails extends VerticalLayout implements View { PrintWriter writer = new PrintWriter(out); e.printStackTrace(writer); errorMessage.setValue(errorMessage.getValue() + "\n" + e.getMessage() + "\n" + out.toString()); + LOGGER.error("Fehler beim Versenden an " + adresses, e); + } + catch (EmailException e) { + + StringWriter out = new StringWriter(); + PrintWriter writer = new PrintWriter(out); + e.printStackTrace(writer); + errorMessage.setValue(errorMessage.getValue() + "\n" + e.getMessage() + "\n" + out.toString()); + LOGGER.error("Fehler beim Versenden an diese Andressen: " + e.getFailedEmails(), e); } });