Skip to content

Commit

Permalink
logToFile option (in addition to redirectToFile) for mail, sms, custo…
Browse files Browse the repository at this point in the history
…m transports
  • Loading branch information
mederly committed Jul 28, 2017
1 parent fd6d7b1 commit 26800a2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
Expand Up @@ -79,6 +79,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="logToFile" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
In addition to sending mail via SMTP, writes all messages to a file. Useful for debugging.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>

Expand Down Expand Up @@ -222,6 +229,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="logToFile" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
In addition to sending messages via SMS, writes all messages to a file. Useful for debugging.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
Expand Down Expand Up @@ -276,6 +290,13 @@
</xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="logToFile" type="xsd:string" minOccurs="0">
<xsd:annotation>
<xsd:documentation>
In addition to executing the expression, writes all messages to a file. Useful for debugging.
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
Expand Down
Expand Up @@ -113,7 +113,10 @@ public void send(Message message, String transportName, Event event, Task task,
result.recordWarning(msg);
return;
}

String logToFile = configuration.getLogToFile();
if (logToFile != null) {
TransportUtil.logToFile(logToFile, TransportUtil.formatToFileNew(message, transportName), LOGGER);
}
String file = configuration.getRedirectToFile();
if (file != null) {
writeToFile(message, file, result);
Expand Down
Expand Up @@ -117,6 +117,10 @@ public void send(Message mailMessage, String transportName, Event event, Task ta
// if (mailConfigurationType == null) {
MailConfigurationType mailConfigurationType = systemConfiguration.getNotificationConfiguration().getMail();
// }
String logToFile = mailConfigurationType.getLogToFile();
if (logToFile != null) {
TransportUtil.logToFile(logToFile, formatToFileOld(mailMessage), LOGGER);
}
String redirectToFile = mailConfigurationType.getRedirectToFile();
if (redirectToFile != null) {
TransportUtil.appendToFile(redirectToFile, formatToFileOld(mailMessage), LOGGER, result);
Expand Down
Expand Up @@ -125,6 +125,10 @@ public void send(Message message, String transportName, Event event, Task task,
}

SmsConfigurationType smsConfigurationType = found;
String logToFile = smsConfigurationType.getLogToFile();
if (logToFile != null) {
TransportUtil.logToFile(logToFile, TransportUtil.formatToFileNew(message, transportName), LOGGER);
}
String file = smsConfigurationType.getRedirectToFile();
if (file != null) {
writeToFile(message, file, null, result);
Expand Down
Expand Up @@ -66,11 +66,19 @@ public static void appendToFile(String fileName, String messageText, Trace logge
TransportUtil.appendToFile(fileName, messageText);
result.recordSuccess();
} catch (Throwable t) {
LoggingUtils.logException(logger, "Couldn't write the notification to a file {}", t, fileName);
LoggingUtils.logUnexpectedException(logger, "Couldn't write the notification to a file {}", t, fileName);
result.recordPartialError("Couldn't write the notification to a file " + fileName, t);
}
}

public static void logToFile(String fileName, String messageText, Trace logger) {
try {
TransportUtil.appendToFile(fileName, messageText);
} catch (Throwable t) {
LoggingUtils.logUnexpectedException(logger, "Couldn't write the notification to a file {}", t, fileName);
}
}

public static String formatToFileOld(Message message) {
return "============================================ " + "\n" +new Date() + "\n" + message.toString() + "\n\n";
}
Expand Down

0 comments on commit 26800a2

Please sign in to comment.