log to temp file.

master
Markus Kreth 6 years ago
parent 1de86c5cdd
commit 4e2445486e
  1. 4
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/email/MuttEmailCommand.java
  2. 15
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/navigation/SendEmails.java

@ -18,7 +18,7 @@ public class MuttEmailCommand implements EmailCommand {
final List<String> arguments = createArguments(email); final List<String> arguments = createArguments(email);
final List<String> errors = new ArrayList<>(); final List<String> errors = new ArrayList<>();
File log = new File("email.log"); File log = File.createTempFile("email_output", ".log");
List<String> adresses = email.getEmails(); List<String> adresses = email.getEmails();
for (String adress : adresses) { for (String adress : adresses) {
List<ProcessBuilder> builders = new ArrayList<>(); List<ProcessBuilder> builders = new ArrayList<>();
@ -50,7 +50,7 @@ public class MuttEmailCommand implements EmailCommand {
} }
if (errors.isEmpty() == false) { if (errors.isEmpty() == false) {
throw new RuntimeException("Errors: " + errors); throw new EmailException("Fehler beim Senden. Log File: " + log.getAbsolutePath(), errors);
} }
} }

@ -10,6 +10,8 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import com.vaadin.data.HasValue.ValueChangeEvent; 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.data.Person;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.email.Email; import de.kreth.vaadin.clubhelper.vaadinclubhelper.email.Email;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.email.EmailCommand; 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.ClubhelperMenuBar;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.MenuItemStateFactory; import de.kreth.vaadin.clubhelper.vaadinclubhelper.ui.components.menu.MenuItemStateFactory;
public class SendEmails extends VerticalLayout implements View { public class SendEmails extends VerticalLayout implements View {
private static final Logger LOGGER = LoggerFactory.getLogger(SendEmails.class);
private PersonBusiness personBusiness; private PersonBusiness personBusiness;
private List<GroupDef> allGroups; private List<GroupDef> allGroups;
@ -141,6 +146,7 @@ public class SendEmails extends VerticalLayout implements View {
.setMessage(body.getValue()) .setMessage(body.getValue())
.addEmails(adresses) .addEmails(adresses)
.build(); .build();
LOGGER.info("Versende an {}: {}", adresses, email);
try { try {
emailCommand.send(email); emailCommand.send(email);
} }
@ -149,6 +155,15 @@ public class SendEmails extends VerticalLayout implements View {
PrintWriter writer = new PrintWriter(out); PrintWriter writer = new PrintWriter(out);
e.printStackTrace(writer); e.printStackTrace(writer);
errorMessage.setValue(errorMessage.getValue() + "\n" + e.getMessage() + "\n" + out.toString()); 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);
} }
}); });

Loading…
Cancel
Save